-
Notifications
You must be signed in to change notification settings - Fork 29
Add DayZ workshop mod updates #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
JustABiologist
wants to merge
4
commits into
Osiris-Team:master
from
JustABiologist:bounty/dayz-mod-update-215
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
92d094e
Add DayZ workshop mod updates
JustABiologist b6604e2
Generalize Steam Workshop mod updater
JustABiologist 39f93ce
Integrate Steam Workshop mods into updater flow
JustABiologist 2c6f735
Check Steam Workshop metadata before updating mods
JustABiologist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
89 changes: 89 additions & 0 deletions
89
src/main/java/com/osiris/autoplug/client/tasks/updater/mods/SteamWorkshopMod.java
This file contains hidden or 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,89 @@ | ||
| /* | ||
| * Copyright (c) 2024 Osiris-Team. | ||
| * All rights reserved. | ||
| * | ||
| * This software is copyrighted work, licensed under the terms | ||
| * of the MIT-License. Consult the "LICENSE" file for details. | ||
| */ | ||
|
|
||
| package com.osiris.autoplug.client.tasks.updater.mods; | ||
|
|
||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileNotFoundException; | ||
| import java.io.IOException; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
|
|
||
| public class SteamWorkshopMod { | ||
| private final File directory; | ||
| private final String name; | ||
| private final String publishedId; | ||
|
|
||
| public SteamWorkshopMod(File directory, String name, String publishedId) { | ||
| this.directory = directory; | ||
| this.name = name; | ||
| this.publishedId = publishedId; | ||
| } | ||
|
|
||
| public File getDirectory() { | ||
| return directory; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public String getPublishedId() { | ||
| return publishedId; | ||
| } | ||
|
|
||
| @NotNull | ||
| public static List<SteamWorkshopMod> findIn(File dir) throws IOException { | ||
| if (!dir.exists()) throw new FileNotFoundException("Directory does not exist: " + dir); | ||
| List<SteamWorkshopMod> mods = new ArrayList<>(); | ||
| File[] files = dir.listFiles(); | ||
| if (files == null) return mods; | ||
| Arrays.sort(files, Comparator.comparing(File::getName)); | ||
| for (File file : files) { | ||
| if (!file.isDirectory()) continue; | ||
| File metaFile = new File(file, "meta.cpp"); | ||
| if (metaFile.exists()) | ||
| mods.add(readFromMeta(file, metaFile)); | ||
| } | ||
| return mods; | ||
| } | ||
|
|
||
| static SteamWorkshopMod readFromMeta(File modDir, File metaFile) throws IOException { | ||
| String name = modDir.getName(); | ||
| String publishedId = null; | ||
| for (String line : Files.readAllLines(metaFile.toPath(), StandardCharsets.UTF_8)) { | ||
| String trimmedLine = line.trim(); | ||
| if (trimmedLine.isEmpty() || trimmedLine.startsWith("//")) continue; | ||
|
|
||
| int equalsIndex = trimmedLine.indexOf('='); | ||
| if (equalsIndex < 0) continue; | ||
|
|
||
| String key = trimmedLine.substring(0, equalsIndex).trim(); | ||
| String value = trimmedLine.substring(equalsIndex + 1).trim(); | ||
| int semicolonIndex = value.indexOf(';'); | ||
| if (semicolonIndex < 0) continue; | ||
| value = value.substring(0, semicolonIndex).trim(); | ||
| if (value.startsWith("\"") && value.endsWith("\"") && value.length() >= 2) | ||
| value = value.substring(1, value.length() - 1); | ||
|
|
||
| if (key.equals("name")) name = value; | ||
| if (key.equals("publishedid")) publishedId = value; | ||
| } | ||
|
|
||
| if (publishedId == null || !publishedId.matches("\\d+")) | ||
| throw new IOException("Failed to read publishedid from " + metaFile); | ||
|
|
||
| return new SteamWorkshopMod(modDir, name, publishedId); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
68 changes: 68 additions & 0 deletions
68
src/test/java/com/osiris/autoplug/client/tasks/updater/mods/SteamWorkshopModTest.java
This file contains hidden or 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,68 @@ | ||
| /* | ||
| * Copyright (c) 2024 Osiris-Team. | ||
| * All rights reserved. | ||
| * | ||
| * This software is copyrighted work, licensed under the terms | ||
| * of the MIT-License. Consult the "LICENSE" file for details. | ||
| */ | ||
|
|
||
| package com.osiris.autoplug.client.tasks.updater.mods; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
|
|
||
| import java.io.File; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| class SteamWorkshopModTest { | ||
|
Osiris-Team marked this conversation as resolved.
|
||
|
|
||
| @TempDir | ||
| Path tempDir; | ||
|
|
||
| @Test | ||
| void readsPublishedIdAndNameFromMetaCpp() throws Exception { | ||
| File modDir = tempDir.resolve("@CF").toFile(); | ||
| modDir.mkdirs(); | ||
| File metaFile = writeMeta(modDir, | ||
| "protocol = 1;", | ||
| "publishedid = 1559212036;", | ||
| "name = \"CF\";", | ||
| "timestamp = 5249804932187309401;"); | ||
|
|
||
| SteamWorkshopMod mod = SteamWorkshopMod.readFromMeta(modDir, metaFile); | ||
|
|
||
| assertEquals(modDir, mod.getDirectory()); | ||
| assertEquals("CF", mod.getName()); | ||
| assertEquals("1559212036", mod.getPublishedId()); | ||
| } | ||
|
|
||
| @Test | ||
| void findsModsWithMetaCppInDirectSubdirectories() throws Exception { | ||
| File firstModDir = tempDir.resolve("@CF").toFile(); | ||
| File secondModDir = tempDir.resolve("@CommunityOnlineTools").toFile(); | ||
| File ignoredDir = tempDir.resolve("keys").toFile(); | ||
| firstModDir.mkdirs(); | ||
| secondModDir.mkdirs(); | ||
| ignoredDir.mkdirs(); | ||
| writeMeta(firstModDir, "publishedid = 1559212036;", "name = \"CF\";"); | ||
| writeMeta(secondModDir, "publishedid = 1564026768;", "name = \"Community-Online-Tools\";"); | ||
|
|
||
| List<SteamWorkshopMod> mods = SteamWorkshopMod.findIn(tempDir.toFile()); | ||
|
|
||
| assertEquals(2, mods.size()); | ||
| assertEquals("1559212036", mods.get(0).getPublishedId()); | ||
| assertEquals("1564026768", mods.get(1).getPublishedId()); | ||
| } | ||
|
|
||
| private File writeMeta(File modDir, String... lines) throws Exception { | ||
| File metaFile = new File(modDir, "meta.cpp"); | ||
| Files.write(metaFile.toPath(), Arrays.asList(lines), StandardCharsets.UTF_8); | ||
| return metaFile; | ||
| } | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.