Patcher/README.md

147 lines
5 KiB
Markdown
Raw Normal View History

2024-12-08 13:41:19 +01:00
<p align="center">
<img src="https://weforge.xyz/Spitfire/Branding/raw/branch/main/active/search/icon-alt4.svg" alt="Logo" width="64" height="64">
</p>
<p align="center" style="font-size: 32px;">
<strong>Spitfire Patcher</strong>
</p>
<p align="center">
2024-12-11 16:41:49 +01:00
This is a custom patcher for applying modifications to Firefox source code. It processes patch files located in the `./patches` directory and applies them to files in a specified root path.
2024-12-08 13:41:19 +01:00
</p>
## How to Use
1. Place your patch files in the `./patches` directory. Example of patch file:
```patch
2024-12-08 17:51:31 +01:00
i:/browser/branding/official/configure.sh
o:/browser/branding/official/configure.sh
2024-12-08 13:41:19 +01:00
-MOZ_APP_DISPLAYNAME=Firefox
+MOZ_APP_DISPLAYNAME=Spitfire
```
2024-12-11 16:41:49 +01:00
2. Run the patcher with the `--path` and `--patches` flags:
2024-12-08 13:41:19 +01:00
```sh
2024-12-11 16:41:49 +01:00
./run.sh --path ./mozilla-central/obj-x86_64-pc-linux-gnu/dist/bin --patches ./mozilla-central/patcher/post-compile-patches
2024-12-08 13:41:19 +01:00
```
2024-12-11 16:41:49 +01:00
- --path *Will be resolved to an absolute path, and patches will be applied relative to this path.*
- --patches *Specifies a path to a `.patch` file or a folder containing patches to be applied by this script*
2024-12-08 17:51:31 +01:00
## Parameters Explained
Here are the details of each parameter used in the patching system:
### **`i:` (Input)**
- Specifies the input file to which the patch should be applied.
- This is the file that will be read and modified based on the patch instructions.
- **Example:**
2024-12-11 16:41:49 +01:00
```patch
2024-12-08 17:51:31 +01:00
i:/browser/branding/official/configure.sh
```
- This means the input file is located at `/browser/branding/official/configure.sh`.
### **`o:` (Output)**
- Specifies the output file where the modified content will be saved.
- If the input and output paths are the same, the original file will be overwritten.
- **Example:**
2024-12-11 16:41:49 +01:00
```patch
2024-12-08 17:51:31 +01:00
o:/browser/branding/official/configure.sh
```
- This means the output file is `/browser/branding/official/configure.sh`.
### **`t:` (Type)**
- Defines the type of patch being applied. This parameter can be skipped if not applicable.
- Common types:
2024-12-11 16:41:49 +01:00
1. **`standard`:** Standard patching type that follows the `+` (add) and `-` (remove) syntax.
- Used for general file modifications.
2024-12-08 17:51:31 +01:00
- **Example:**
2024-12-11 16:41:49 +01:00
```patch
2024-12-13 12:23:51 +01:00
i: /browser/branding/official/configure.sh
o: /browser/branding/official/configure.sh
2024-12-11 16:41:49 +01:00
-MOZ_APP_DISPLAYNAME=Firefox
+MOZ_APP_DISPLAYNAME=Spitfire
2024-12-08 17:51:31 +01:00
```
2024-12-13 12:23:51 +01:00
Note: *Type will fallback to t:standard when no type is specified.*
2024-12-11 16:41:49 +01:00
2. **`pref`:** Indicates that the patch is modifying preference settings (e.g., Firefox `prefs.js`).
- When `t:pref` is specified, the script will search for existing preferences in the input file and replace them with the new ones provided in the patch. If not found, it will add the new preference.
- **Example:**
```patch
2024-12-08 17:51:31 +01:00
t:pref
2024-12-13 12:23:51 +01:00
i:/browser/branding/nightly/pref/firefox-branding.js
o:/browser/branding/nightly/pref/firefox-branding.js
2024-12-08 17:51:31 +01:00
+pref("extensions.getAddons.showPane", false); // HIDDEN
```
2024-12-11 16:41:49 +01:00
3. **`new`:** Used for creating new files or overwriting existing files with specified content.
- Creates a new file at the `o:` location.
2024-12-08 17:51:31 +01:00
- **Example:**
2024-12-11 16:41:49 +01:00
```patch
t:new
o:/browser/branding/official/newfile.txt
+This is a new file created by Spitfire Patcher.
2024-12-08 17:51:31 +01:00
```
2024-12-13 12:23:51 +01:00
4. **`copy`:**: Copies files or directories from the input path to the output path, overwriting if necessary.
- Copies the contents of a file or directory from i: to o:.
- **Example:**
```patch
t:copy
i:/patcher/pre-compile-patches/branding
o:/browser/branding/official
```
2024-12-08 17:51:31 +01:00
2024-12-11 16:41:49 +01:00
### Example Patch Files
2024-12-08 17:51:31 +01:00
2024-12-11 16:41:49 +01:00
```patch
2024-12-08 17:51:31 +01:00
t:pref
2024-12-11 16:41:49 +01:00
i:/browser/firefox.js
o:/browser/spitfire.js
2024-12-08 17:51:31 +01:00
-pref("browser.privatebrowsing.autostart", false);
+pref("browser.privatebrowsing.autostart", true);
2024-12-11 16:41:49 +01:00
```
2024-12-08 17:51:31 +01:00
2024-12-11 16:41:49 +01:00
```patch
2024-12-08 17:51:31 +01:00
t:standard
i:/browser/app/profile/firefox.js
o:/browser/app/profile/firefox.js
-MOZ_APP_DISPLAYNAME=Firefox
+MOZ_APP_DISPLAYNAME=Spitfire
```
2024-12-11 16:41:49 +01:00
```patch
t:new
o:/browser/branding/official/new-file.txt
+Welcome to Spitfire Browser Branding.
```
2024-12-08 17:51:31 +01:00
### Summary of Parameters
| Parameter | Required | Purpose | Example |
| ----------- | ---------- | ------------------------------------- | ------------------------------------- |
| `i:` | Yes | Specifies the input file path. | `i:/browser/app/profile/firefox.js` |
| `o:` | Yes | Specifies the output file path. | `o:/browser/app/profile/firefox.js` |
2024-12-13 12:23:51 +01:00
| `t:` | No | Defines the type of patch. | `t:pref`, `t:standard`, `t:new`, or `t:move` |
2024-12-08 17:51:31 +01:00
| `+` | Yes | Adds a line to the output file. | `+MOZ_APP_DISPLAYNAME=Spitfire` |
| `-` | Yes | Removes a line from the input file. | `-MOZ_APP_DISPLAYNAME=Firefox` |
### Workflow
1. **Define Input and Output:** Use `i:` and `o:` to specify which files to read and write.
2. **Specify Patch Type:** Use `t:` for special handling like preference modifications.
3. **Apply Modifications:** Use `+` to add lines and `-` to remove lines.