This repository has been archived by the owner on Oct 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from tygoee/dev
Moved some things around
- Loading branch information
Showing
17 changed files
with
374 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Python: Install", | ||
"type": "python", | ||
"request": "launch", | ||
"program": "${file}", | ||
"console": "integratedTerminal", | ||
"justMyCode": true, | ||
"args": [ | ||
"install", | ||
"-y" | ||
] | ||
} | ||
] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# MCM-Manager: Minecraft Modpack Manager | ||
# Copyright (C) 2023 Tygo Everts | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
from os import path | ||
|
||
|
||
class maven_parse: | ||
def __init__(self, arg: str) -> None: | ||
""" | ||
Parse java maven coords to a folder and a file. | ||
Example: | ||
```txt | ||
de.oceanlabs.mcp:mcp_config:1.20.1-20230612.114412@zip | ||
- folder: de/oceanlabs/mcp/mcp_config/1.20.1-20230612.114412/ | ||
- file: mcp_config-1.20.1-20230612.114412.zip | ||
``` | ||
You can get a file path using `.maven_to_file()` | ||
or an url using `.maven_to_url`. | ||
To directly access the parsed result, | ||
use the variable `.parsed` | ||
""" | ||
|
||
self.parsed = self._parse(arg) | ||
|
||
def _parse(self, arg: str) -> tuple[str, str]: | ||
# Split the file extension | ||
if '@' in arg: | ||
arg, ext = arg.split('@', 1) | ||
else: | ||
ext = 'jar' | ||
|
||
# Until the third colon, replace | ||
# ':' with path.sep. Until the | ||
# first, also replace '.' with it | ||
colons = 0 | ||
folder = '' | ||
for char in arg: | ||
if colons == 3: | ||
break | ||
if char == ':': | ||
colons += 1 | ||
char = path.sep | ||
elif char == '.' and colons == 0: | ||
char = path.sep | ||
folder += char | ||
|
||
if not folder[-1] == '/': | ||
folder += '/' | ||
|
||
# Select everything from the first | ||
# colon and replace ':' with '-' | ||
file = '' | ||
for char in arg[arg.find(':')+1:]: | ||
if char == ':': | ||
char = '-' | ||
file += char | ||
|
||
# Add the file extension | ||
file += '.' + ext | ||
|
||
return folder, file | ||
|
||
def to_file(self, *paths: str) -> str: | ||
""" | ||
Create a file path from the maven coord. This calls | ||
a `path.join()` with all paths plus `self.parsed` | ||
""" | ||
return path.join(*paths, *self.parsed) | ||
|
||
def to_url(self, base: str) -> str: | ||
"""Create a url from the maven coord""" | ||
if not base[-1] == '/': | ||
base += '/' | ||
|
||
return ''.join((base, *self.parsed)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +0,0 @@ | ||
# MCM-Manager: Minecraft Modpack Manager | ||
# Copyright (C) 2023 Tygo Everts | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
from os import path, mkdir | ||
from json import dump | ||
from .vars import install_dir, launcher_dir | ||
|
||
# Create the install dir | ||
if not path.isdir(install_dir): | ||
mkdir(install_dir) | ||
|
||
# Create the launcher dir and example-manifest.json | ||
if not path.isdir(launcher_dir): | ||
mkdir(launcher_dir) | ||
|
||
launcher_profiles = { | ||
"profiles": {}, | ||
"settings": { | ||
"crashAssistance": True, | ||
"enableAdvanced": False, | ||
"enableAnalytics": True, | ||
"enableHistorical": False, | ||
"enableReleases": True, | ||
"enableSnapshots": False, | ||
"keepLauncherOpen": False, | ||
"profileSorting": "ByLastPlayed", | ||
"showGameLog": False, | ||
"showMenu": False, | ||
"soundOn": False | ||
}, | ||
"version": 3 | ||
} | ||
|
||
with open(path.join(launcher_dir, 'launcher_profiles.json'), 'w') as fp: | ||
dump(launcher_profiles, fp, indent=4) | ||
|
||
del path, mkdir, dump, install_dir, launcher_dir, launcher_profiles, fp | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"profiles": {}, | ||
"settings": { | ||
"crashAssistance": true, | ||
"enableAdvanced": false, | ||
"enableAnalytics": true, | ||
"enableHistorical": false, | ||
"enableReleases": true, | ||
"enableSnapshots": false, | ||
"keepLauncherOpen": false, | ||
"profileSorting": "ByLastPlayed", | ||
"showGameLog": false, | ||
"showMenu": false, | ||
"soundOn": false | ||
}, | ||
"version": 3 | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# MCM-Manager: Minecraft Modpack Manager | ||
# Copyright (C) 2023 Tygo Everts | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
import unittest | ||
|
||
from src.common.maven_coords import maven_parse | ||
|
||
|
||
class MavenParse(unittest.TestCase): | ||
def test_maven_coords(self): | ||
cases: list[tuple[str, tuple[str, str], str, str]] = [ | ||
( # With three parts | ||
'net.fabricmc:fabric-loader:0.14.22', ( | ||
'net/fabricmc/fabric-loader/0.14.22/', | ||
'fabric-loader-0.14.22.jar' | ||
), | ||
'libraries/net/fabricmc/fabric-loader/0.14.22/' | ||
'fabric-loader-0.14.22.jar', | ||
'https://example.com/net/fabricmc/fabric-loader' | ||
'/0.14.22/fabric-loader-0.14.22.jar' | ||
), | ||
( # With four parts | ||
'net.minecraft:client:1.20.1-20230612.114412:slim', ( | ||
'net/minecraft/client/1.20.1-20230612.114412/', | ||
'client-1.20.1-20230612.114412-slim.jar' | ||
), | ||
'libraries/net/minecraft/client/1.20.1-20230612.114412/' | ||
'client-1.20.1-20230612.114412-slim.jar', | ||
'https://example.com/net/minecraft/client/' | ||
'1.20.1-20230612.114412/client-1.20.1-20230612.114412-slim.jar' | ||
), | ||
( # With three parts and a file extension | ||
'de.oceanlabs.mcp:mcp_config:1.20.1-20230612.114412@zip', ( | ||
'de/oceanlabs/mcp/mcp_config/1.20.1-20230612.114412/', | ||
'mcp_config-1.20.1-20230612.114412.zip' | ||
), | ||
'libraries/de/oceanlabs/mcp/mcp_config/1.20.1-20230612.114412/' | ||
'mcp_config-1.20.1-20230612.114412.zip', | ||
'https://example.com/de/oceanlabs/mcp/mcp_config/' | ||
'1.20.1-20230612.114412/mcp_config-1.20.1-20230612.114412.zip' | ||
), | ||
( # With four parts and a file extension | ||
'de.oceanlabs.mcp:mcp_config:1.20.1-20230612.114412:mappings@txt', ( | ||
'de/oceanlabs/mcp/mcp_config/1.20.1-20230612.114412/', | ||
'mcp_config-1.20.1-20230612.114412-mappings.txt' | ||
), | ||
'libraries/de/oceanlabs/mcp/mcp_config/1.20.1-20230612.114412/' | ||
'mcp_config-1.20.1-20230612.114412-mappings.txt', | ||
'https://example.com/de/oceanlabs/mcp/mcp_config/' | ||
'1.20.1-20230612.114412/mcp_config-1.20.1-20230612.114412-mappings.txt' | ||
) | ||
] | ||
|
||
for i in cases: | ||
maven = maven_parse(i[0]) | ||
self.assertEqual(maven.parsed, i[1]) | ||
self.assertEqual(maven.to_file('libraries'), i[2]) | ||
self.assertEqual(maven.to_url('https://example.com'), i[3]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# MCM-Manager: Minecraft Modpack Manager | ||
# Copyright (C) 2023 Tygo Everts | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
from os import path | ||
|
||
CURDIR = path.dirname(path.realpath(__file__)) | ||
|
||
TMPDIR = path.join(CURDIR, 'temp') | ||
LAUNDIR = path.join(TMPDIR, '.minecraft') | ||
INSTDIR = path.join(TMPDIR, 'gamedir') | ||
|
||
ASSETDIR = path.join(CURDIR, 'assets') | ||
MANIFEST = path.join(ASSETDIR, 'manifest.json') | ||
LAUNPROF = path.join(ASSETDIR, 'launcher_profiles.json') |
Oops, something went wrong.