Skip to content

Commit

Permalink
搜索整合包,修正换行符和bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Wulian233 committed Aug 2, 2024
1 parent a479093 commit 24d211c
Show file tree
Hide file tree
Showing 11 changed files with 530 additions and 502 deletions.
8 changes: 4 additions & 4 deletions PyBuild/win_build.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@echo off
cd..
pip install -r requirements.txt
pip install pyinstaller
@echo off
cd..
pip install -r requirements.txt
pip install pyinstaller
pyinstaller main.spec
103 changes: 55 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,56 @@
<div align="center">
<img height="100px" width="100px" alt="logo" src="PyBuild/icon.png"/>
<h1>Feed The Forge</h1>
</div>

## Introduce
This is a simple tool to download modpacks from FTB without the need of the FTB Launcher.

You can then import or drag this zip file into any curseforge compatible launcher.

For example: HMCL, PCL2, Prism Launcher etc.

## Usage
WIP

## Develop and Build
### Requirements

- **Python Version**: 3.8+
- **Supported Operating Systems**: Windows 10 or later, macOS, Linux

### Running from Source

1. **Install Dependencies**:
- Open a terminal and run the following command to install required packages:
```bash
pip install -r requirements.txt
```

2. **Run**:
- After installing the dependencies, run `__main__.py`

### Building Executable for Windows

1. **Package as Executable**:
- To package the application as an executable for Windows, run the following script:
```bash
cd PyBuild
win_build.bat
```

2. **Locate the Executable**:
- The resulting `.exe` file will be located in the `dist` folder.

3. **Additional Steps**:
- Copy the `feedtheforge/lang` folder to the same directory as the `.exe` file to ensure the application runs correctly.

## LICENSE
<div align="center">
<img height="100px" width="100px" alt="logo" src="PyBuild/icon.png"/>
<h1>Feed The Forge</h1>
</div>

## Introduce
This is a simple tool to download modpacks from FTB without the need of the FTB Launcher.

You can then import or drag this zip file into any curseforge compatible launcher.

For example: HMCL, PCL2, Prism Launcher etc.

## Usage
WIP

## Develop and Build
### Requirements
- **Git**: 3.8+
- **Python Version**: 3.8+
- **Supported Operating Systems**: Windows 10 or later, macOS, Linux

### Running from Source

1. **Install Dependencies**:
- Open a terminal and run the following command to install required packages:
```bash
git clone https://github.com/Wulian233/FeedTheForge.git
cd FeedTheForge
pip install -r requirements.txt
```

2. **Run**:
- After installing the dependencies, run `__main__.py`

### Building Executable for Windows

1. **Package as Executable**:
- To package the application as an executable for Windows, run the following script:
- Windows
```bash
cd PyBuild
win_build.bat
```
- Unix
```bash
cd PyBuild
unix_build.sh
```
2. **Locate the Executable**:
- The resulting `.exe` file will be located in the `dist` folder.

3. **Additional Steps**:
- Copy the `feedtheforge/lang` folder to the `dist` directory

## LICENSE
[GNU General Public License v3.0](.LICENSE)
26 changes: 13 additions & 13 deletions __main__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
if __name__ == "__main__":
import asyncio
import sys
from main import *
from feedtheforge.utils import pause

py_version = sys.version_info

if not (3, 8) < py_version < (3, 15):
print(lang.t("feedtheforge.main.unsupported_version",
cur=f"{py_version.major}.{py_version.minor}.{py_version.micro}"))
pause()
asyncio.run(main())
if __name__ == "__main__":
import asyncio
import sys
from main import *
from feedtheforge.utils import pause

py_version = sys.version_info

if not (3, 8) < py_version < (3, 15):
print(lang.t("feedtheforge.main.unsupported_version",
cur=f"{py_version.major}.{py_version.minor}.{py_version.micro}"))
pause()
asyncio.run(main())

83 changes: 41 additions & 42 deletions feedtheforge/const.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
import locale
import os
import tempfile

from feedtheforge.i18n import Locale

# 自动切换语言
if locale._getdefaultlocale()[0] == "zh_CN":
lang = Locale("zh_CN")
else:
lang = Locale("en_US")

current_language = lang.get_language()

cache_dir = os.path.join(tempfile.gettempdir(), "FeedTheForge")
packlist_path = os.path.join(cache_dir, "packlist.json")
modpack_path = os.path.join(cache_dir, "pack_files")

patch = os.path.join(cache_dir, "patch.zip")
patch_folder = os.path.join(cache_dir, "patch")
i18nupdate_link = "https://mediafilez.forgecdn.net/files/5335/196/I18nUpdateMod-3.5.5-all.jar"
mod_path = os.path.join(modpack_path, "overrides", "mods")

api_list = "https://api.modpacks.ch/public/modpack/all"
api_featured = "https://api.modpacks.ch/public/modpack/featured/20"
api_search = "https://api.modpacks.ch/public/modpack/search/20/detailed?platform=modpacksch&term="

# 全部汉化 key: FTB唯一包版本 vaule: 蓝奏云汉化下载链接
# TODO 未来应单独做出一个json并联网更新,不宜写死。支持匹配id全部版本支持
all_patch = {
# 100 StoneBlock 3
"6498": "https://wulian233.lanzouj.com/iwAZ61xg3yib",
"6647": "https://wulian233.lanzouj.com/iwAZ61xg3yib",
"6967": "https://wulian233.lanzouj.com/iwAZ61xg3yib",
"11655": "https://wulian233.lanzouj.com/iwAZ61xg3yib",
# 115 Arcanum Institute
"11512": "https://vmhanhuazu.lanzouj.com/i8W7Y1nr83le",
# 122 Builders Paradise 2
"11840": "https://wulian233.lanzouj.com/ib5G81wnrpwb",
"11937": "https://wulian233.lanzouj.com/ib5G81wnrpwb",
"12266": "https://wulian233.lanzouj.com/ib5G81wnrpwb"
}
import locale
import os
import tempfile

from feedtheforge.i18n import Locale

# 自动切换语言
default_locale = locale.getdefaultlocale()[0]
lang = Locale("zh_CN" if default_locale == "zh_CN" else "en_US")
current_language = lang.get_language()

# 缓存目录设置
cache_dir = os.path.join(tempfile.gettempdir(), "FeedTheForge")
packlist_path = os.path.join(cache_dir, "packlist.json")
modpack_path = os.path.join(cache_dir, "pack_files")
patch = os.path.join(cache_dir, "patch.zip")
patch_folder = os.path.join(cache_dir, "patch")
mod_path = os.path.join(modpack_path, "overrides", "mods")

I18NUPDATE_LINK = "https://mediafilez.forgecdn.net/files/5335/196/I18nUpdateMod-3.5.5-all.jar"

# API链接
API_LIST = "https://api.modpacks.ch/public/modpack/all"
API_FEATURED = "https://api.modpacks.ch/public/modpack/featured/20"
API_SEARCH = "https://api.modpacks.ch/public/modpack/search/20/detailed?platform=modpacksch&term="

# 全部汉化 key: FTB唯一包版本 vaule: 蓝奏云汉化下载链接
# TODO 未来应单独做出一个json并联网更新,不宜写死。支持匹配id全部版本支持
all_patch = {
# 100 StoneBlock 3
"6498": "https://wulian233.lanzouj.com/iwAZ61xg3yib",
"6647": "https://wulian233.lanzouj.com/iwAZ61xg3yib",
"6967": "https://wulian233.lanzouj.com/iwAZ61xg3yib",
"11655": "https://wulian233.lanzouj.com/iwAZ61xg3yib",
# 115 Arcanum Institute
"11512": "https://vmhanhuazu.lanzouj.com/i8W7Y1nr83le",
# 122 Builders Paradise 2
"11840": "https://wulian233.lanzouj.com/ib5G81wnrpwb",
"11937": "https://wulian233.lanzouj.com/ib5G81wnrpwb",
"12266": "https://wulian233.lanzouj.com/ib5G81wnrpwb"
}
78 changes: 39 additions & 39 deletions feedtheforge/i18n.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import json
from pathlib import Path
from string import Template


class Locale:
def __init__(self, lang: str):
self.lang = lang
self.path = Path(f"./feedtheforge/lang/{lang}.json")
self.data = {}
self.load()

def __getitem__(self, key: str):
return self.data[key]

def __contains__(self, key: str):
return key in self.data

def load(self):
with open(self.path, "r", encoding="utf-8") as f:
d = f.read()
self.data = json.loads(d)
f.close()

def get_string(self, key: str, failed_prompt):
n = self.data.get(key, None)
if n != None:
return n
if failed_prompt:
return str(key) + self.t("feedtheforge.i18n.failed")
return key

def t(self, key: str, failed_prompt=True, *args, **kwargs):
localized = self.get_string(key, failed_prompt)
return Template(localized).safe_substitute(*args, **kwargs)

def get_language(self):
return self.lang

import json
from pathlib import Path
from string import Template


class Locale:
def __init__(self, lang: str):
self.lang = lang
self.path = Path(f"./feedtheforge/lang/{lang}.json")
self.data = {}
self.load()

def __getitem__(self, key: str):
return self.data[key]

def __contains__(self, key: str):
return key in self.data

def load(self):
with open(self.path, "r", encoding="utf-8") as f:
d = f.read()
self.data = json.loads(d)
f.close()

def get_string(self, key: str, failed_prompt):
n = self.data.get(key, None)
if n != None:
return n
if failed_prompt:
return str(key) + self.t("feedtheforge.i18n.failed")
return key

def t(self, key: str, failed_prompt=True, *args, **kwargs):
localized = self.get_string(key, failed_prompt)
return Template(localized).safe_substitute(*args, **kwargs)

def get_language(self):
return self.lang

lang = Locale("zh_CN")
63 changes: 32 additions & 31 deletions feedtheforge/lang/en_US.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
{
"feedtheforge.start.title": "Press Up or Down to select, Enter to confirm:",
"feedtheforge.start.featured_modpack": "View Featured Modpacks",
"feedtheforge.start.featured_modpack_desc": "View and download the top 5 modpacks of the last 20 days",
"feedtheforge.start.search_modpack": "Search Modpacks",
"feedtheforge.start.search_modpack_desc": "Enter English keywords to search for modpacks, then select to download",
"feedtheforge.start.enter_id": "Enter Modpack ID",
"feedtheforge.start.enter_id_desc": "Directly enter the numeric ID of the modpack to download",
"feedtheforge.start.clean_temp": "Clean Cache",
"feedtheforge.start.clean_temp_desc": "Clear cached modpack information. The next startup will be slower",
"feedtheforge.start.exit": "Exit",
"feedtheforge.start.exit_desc": "Exit the tool and close the window",

"feedtheforge.main.clean_temp": "Cache cleaned successfully, a total of $size KB was cleaned",
"feedtheforge.main.default_version": "Automatically selected the latest version $selected_version",
"feedtheforge.main.enter_id": "Please enter the ID of the modpack to download:",
"feedtheforge.main.enter_version": "Please enter the modpack version (leave blank for latest):",
"feedtheforge.main.getting_error": "Network error, failed to retrieve modpack list.",
"feedtheforge.main.getting_list": "Getting modpacks list...",
"feedtheforge.main.has_chinese_patch": "Don't show in English",
"feedtheforge.main.search_modpack": "Please enter keywords for the modpack:",
"feedtheforge.main.invalid_pack_id": "No corresponding modpack found. Please enter a valid modpack ID",
"feedtheforge.main.invalid_modpack_version": "No corresponding modpack version found. Please enter a valid version.",
"feedtheforge.main.unsupported_version": "This program requires Python 3.8+ to run. The current version is Python $cur .",
"feedtheforge.main.version_list": "Available versions for the current modpack: $version_list",
"feedtheforge.main.modpack_created": "Compression successful. A modpack named $modpack_name has been created. Please drag it into the launcher to install",
"feedtheforge.main.modpack_name": "Successfully selected $modpack_name",
"feedtheforge.main.zipping_modpack": "Download completed, creating modpack installation package.",

"feedtheforge.main.pause": "Press Enter to exit",
"feedtheforge.i18n.failed": "Error: No corresponding localization string"
{
"feedtheforge.start.title": "Press Up or Down to select, Enter to confirm:",
"feedtheforge.start.featured_modpack": "View Featured Modpacks",
"feedtheforge.start.featured_modpack_desc": "View and download the top 5 modpacks of the last 20 days",
"feedtheforge.start.search_modpack": "Search Modpacks",
"feedtheforge.start.search_modpack_desc": "Enter English keywords to search for modpacks, then select to download",
"feedtheforge.start.enter_id": "Enter Modpack ID",
"feedtheforge.start.enter_id_desc": "Directly enter the numeric ID of the modpack to download",
"feedtheforge.start.clean_temp": "Clean Cache",
"feedtheforge.start.clean_temp_desc": "Clear cached modpack information. The next startup will be slower",
"feedtheforge.start.exit": "Exit",
"feedtheforge.start.exit_desc": "Exit the tool and close the window",

"feedtheforge.main.clean_temp": "Cache cleaned successfully, a total of $size KB was cleaned",
"feedtheforge.main.default_version": "Automatically selected the latest version $selected_version",
"feedtheforge.main.empty_search": "No keywords entered or search results are empty, no corresponding modpack available",
"feedtheforge.main.enter_id": "Please enter the ID of the modpack to download:",
"feedtheforge.main.enter_version": "Please enter the modpack version (leave blank for latest):",
"feedtheforge.main.getting_error": "Network error, failed to retrieve modpack list.",
"feedtheforge.main.getting_list": "Getting modpacks list...",
"feedtheforge.main.has_chinese_patch": "Don't show in English",
"feedtheforge.main.search_modpack": "Please enter keywords for the modpack:",
"feedtheforge.main.invalid_pack_id": "No corresponding modpack found. Please enter a valid modpack ID",
"feedtheforge.main.invalid_modpack_version": "No corresponding modpack version found. Please enter a valid version.",
"feedtheforge.main.unsupported_version": "This program requires Python 3.8+ to run. The current version is Python $cur .",
"feedtheforge.main.version_list": "Available versions for the current modpack: $version_list",
"feedtheforge.main.modpack_created": "Compression successful. A modpack named $modpack_name has been created. Please drag it into the launcher to install",
"feedtheforge.main.modpack_name": "Successfully selected $modpack_name",
"feedtheforge.main.zipping_modpack": "Download completed, creating modpack installation package.",

"feedtheforge.main.pause": "Press Enter to exit",
"feedtheforge.i18n.failed": "Error: No corresponding localization string"
}
Loading

0 comments on commit 24d211c

Please sign in to comment.