Skip to content
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

18 auto updater v2 #55

Merged
merged 9 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Build/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ To start JASM run "JASM - Just Another Skin Manager.exe" inside JASM folder. You

Updating from previous versions:

Delete the old JASM folder and replace it with the new one.
Personal settings are stored in "C:\Users\<username>\AppData\Local\JASM\ApplicationData" or in the mods themselves
From Version 1.4.3 and upwards -> Click the update button at the bottom of the settings page.

OR

1. Download JASM.
2. Delete the old JASM folder and replace it with the new one.

Personal settings are stored in "C:\Users\<username>\AppData\Local\JASM\ApplicationData" or in the mods themselves


If you have any questions or suggestions, please post them on https://gamebanana.com/tools/14574 or https://github.com/Jorixon/JASM
Expand Down
31 changes: 24 additions & 7 deletions Build/Release.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
JASM_CSPROJ = "src\\GIMI-ModManager.WinUI\\GIMI-ModManager.WinUI.csproj"
JASM_OUTPUT = "src\\GIMI-ModManager.WinUI\\bin\\Release\Publish\\"

JASM_Updater_CSPROJ = "src\\JASM.AutoUpdater\\JASM.AutoUpdater.csproj"
JASM_Updater_OUTPUT = "src\\\\JASM.AutoUpdater\\bin\\Release\Publish\\"
JASM_Updater_FolderName = "JASM - Auto Updater_New"

RELEASE_DIR = "output"
JASM_RELEASE_DIR = "output\\JASM"

def checkSucssfulExitCode(exitCode: int) -> None:
def checkSuccessfulExitCode(exitCode: int) -> None:
if exitCode != 0:
print("Exit code: " + str(exitCode))
exit(exitCode)
Expand All @@ -37,14 +41,21 @@ def extractVersionNumber() -> str:
print("Building Elevator...")
elevatorPublishCommand = "dotnet publish " + ELEVATOR_CSPROJ + " /p:PublishProfile=FolderProfile.pubxml -c Release"
print(elevatorPublishCommand)
checkSucssfulExitCode(os.system(elevatorPublishCommand))
checkSuccessfulExitCode(os.system(elevatorPublishCommand))
print()
print("Finished building Elevator")

print("Building JASM - Auto Updater...")
jasmUpdaterPublishCommand = "dotnet publish " + JASM_Updater_CSPROJ + " /p:PublishProfile=FolderProfile.pubxml -c Release"
print(jasmUpdaterPublishCommand)
checkSuccessfulExitCode(os.system(jasmUpdaterPublishCommand))
print()
print("Finished building JASM - Auto Updater")

print("Building JASM...")
jasmPublishCommand = "dotnet publish " + JASM_CSPROJ + " /p:PublishProfile=FolderProfile.pubxml -c Release"
print(jasmPublishCommand)
checkSucssfulExitCode(os.system(jasmPublishCommand))
checkSuccessfulExitCode(os.system(jasmPublishCommand))
print()
print("Finished building JASM")

Expand All @@ -54,7 +65,7 @@ def extractVersionNumber() -> str:


print("Copying Elevator to JASM...")
checkSucssfulExitCode(os.system("copy " + ELEVATOR_OUTPUT_FILE + " " + JASM_RELEASE_DIR))
checkSuccessfulExitCode(os.system("copy " + ELEVATOR_OUTPUT_FILE + " " + JASM_RELEASE_DIR))
print()
print("Finished copying Elevator to release directory")

Expand All @@ -63,6 +74,12 @@ def extractVersionNumber() -> str:
print()
print("Finished copying JASM to release directory")

print("Copying JASM - Auto Updater to output...")
os.mkdir(JASM_RELEASE_DIR + "\\" + JASM_Updater_FolderName)
shutil.copytree(JASM_Updater_OUTPUT, JASM_RELEASE_DIR + "\\" + JASM_Updater_FolderName, ignore=shutil.ignore_patterns("*.pdb"), dirs_exist_ok=True)
print()
print("Finished copying JASM - Auto Updater to release directory")

print("Copying text files to RELEASE_DIR...")
shutil.copy("Build\\README.txt", RELEASE_DIR)
shutil.copy("CHANGELOG.md", RELEASE_DIR + "\\CHANGELOG.txt")
Expand All @@ -71,8 +88,8 @@ def extractVersionNumber() -> str:

print("Zipping release directory...")
print("7z a -t7z -xm4 JASM.7z " + RELEASE_DIR)
releaseArhciveName = "JASM_v" + versionNumber + ".7z"
checkSucssfulExitCode(os.system(f"7z a -mx4 {releaseArhciveName} .\\{RELEASE_DIR}\\*"))
releaseArchiveName = "JASM_v" + versionNumber + ".7z"
checkSuccessfulExitCode(os.system(f"7z a -mx4 {releaseArchiveName} .\\{RELEASE_DIR}\\*"))
print()
print("Finished zipping release directory")

Expand All @@ -81,7 +98,7 @@ def extractVersionNumber() -> str:
exit(1)

with open(env_file, "a") as myfile:
myfile.write(f"zipFile={releaseArhciveName}")
myfile.write(f"zipFile={releaseArchiveName}")

exit(0)

Expand Down
13 changes: 9 additions & 4 deletions src/GIMI-ModManager.Core/Services/ModCrawlerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public IEnumerable<ISubSkin> GetSubSkinsRecursive(string absPath)

foreach (var file in RecursiveGetFiles(folder))
{
var subSkin = subSkins.FirstOrDefault(skin => IsOfSkinType(file.Name, skin));
var subSkin = subSkins.FirstOrDefault(skin => IsOfSkinType(file, skin));
if (subSkin is null) continue;

_logger.Debug("Detected subSkin {subSkin} for folder {folder}", subSkin.Name, folder.FullName);
Expand All @@ -46,7 +46,7 @@ public IEnumerable<ISubSkin> GetSubSkinsRecursive(string absPath)

foreach (var file in RecursiveGetFiles(folder))
{
var subSkin = subSkins.FirstOrDefault(skin => IsOfSkinType(file.Name, skin));
var subSkin = subSkins.FirstOrDefault(skin => IsOfSkinType(file, skin));
if (subSkin is null) continue;

_logger.Debug("Detected subSkin {subSkin} for folder {folder}", subSkin.Name, folder.FullName);
Expand All @@ -57,10 +57,15 @@ public IEnumerable<ISubSkin> GetSubSkinsRecursive(string absPath)
return null;
}

private static readonly string[] ModExtensions = { ".buf", ".dds", ".ib" };

private static bool IsOfSkinType(string name, ISubSkin skin)
private static bool IsOfSkinType(FileInfo file, ISubSkin skin)
{
return name.Trim().StartsWith(skin.Name, StringComparison.CurrentCultureIgnoreCase);
var fileExtensionMatch = ModExtensions.Any(extension =>
file.Extension.Equals(extension, StringComparison.CurrentCultureIgnoreCase));


return fileExtensionMatch && file.Name.Trim().StartsWith(skin.Name, StringComparison.CurrentCultureIgnoreCase);
}


Expand Down
3 changes: 3 additions & 0 deletions src/GIMI-ModManager.WinUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public static T GetService<T>()

public static UIElement? AppTitlebar { get; set; }

public static bool OverrideShutdown { get; set; }

public App()
{
InitializeComponent();
Expand Down Expand Up @@ -88,6 +90,7 @@ public App()
services.AddSingleton<ThreeDMigtoProcessManager>();

services.AddSingleton<UpdateChecker>();
services.AddSingleton<AutoUpdaterService>();

// Core Services
services.AddSingleton<IFileService, FileService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface ILocalSettingsService

Task<T> ReadOrCreateSettingAsync<T>(string key) where T : new();

Task SaveSettingAsync<T>(string key, T value);
Task SaveSettingAsync<T>(string key, T value) where T : notnull;

T? ReadSetting<T>(string key);
}
30 changes: 23 additions & 7 deletions src/GIMI-ModManager.WinUI/Services/ActivationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ public class ActivationService : IActivationService
private readonly ThreeDMigtoProcessManager _threeDMigtoProcessManager;
private readonly UpdateChecker _updateChecker;
private readonly IWindowManagerService _windowManagerService;
private readonly AutoUpdaterService _autoUpdaterService;
private UIElement? _shell = null;

private readonly bool IsMsix = RuntimeHelper.IsMSIX;


public ActivationService(ActivationHandler<LaunchActivatedEventArgs> defaultHandler,
IEnumerable<IActivationHandler> activationHandlers, IThemeSelectorService themeSelectorService,
ILocalSettingsService localSettingsService,
IGenshinService genshinService, ElevatorService elevatorService, GenshinProcessManager genshinProcessManager,
ThreeDMigtoProcessManager threeDMigtoProcessManager, UpdateChecker updateChecker,
IWindowManagerService windowManagerService)
IWindowManagerService windowManagerService, AutoUpdaterService autoUpdaterService)
{
_defaultHandler = defaultHandler;
_activationHandlers = activationHandlers;
Expand All @@ -47,6 +49,7 @@ public ActivationService(ActivationHandler<LaunchActivatedEventArgs> defaultHand
_threeDMigtoProcessManager = threeDMigtoProcessManager;
_updateChecker = updateChecker;
_windowManagerService = windowManagerService;
_autoUpdaterService = autoUpdaterService;
}

public async Task ActivateAsync(object activationArgs)
Expand All @@ -73,7 +76,7 @@ public async Task ActivateAsync(object activationArgs)
App.MainWindow.Activate();

// Set MainWindow Cleanup on Close.
App.MainWindow.Closed += (_, _) => OnApplicationExit();
App.MainWindow.Closed += OnApplicationExit;

// Execute tasks after activation.
await StartupAsync();
Expand Down Expand Up @@ -109,7 +112,6 @@ private async Task InitializeAsync()
await SetScreenSize();
await _genshinService.InitializeAsync(jsonPath).ConfigureAwait(false);
await _themeSelectorService.InitializeAsync().ConfigureAwait(false);
_elevatorService.Initialize();
}


Expand All @@ -121,6 +123,7 @@ private async Task StartupAsync()
await _genshinProcessManager.TryInitialize();
await _threeDMigtoProcessManager.TryInitialize();
await _updateChecker.InitializeAsync();
await Task.Run(() => _autoUpdaterService.UpdateAutoUpdater()).ConfigureAwait(false);
}

private async Task SetScreenSize()
Expand Down Expand Up @@ -179,8 +182,22 @@ private void ScreenSizeSavingTimer_Tick(object sender, object e)
}


private void OnApplicationExit()
private void OnApplicationExit(object sender, WindowEventArgs args)
{
if (App.OverrideShutdown)
{
_logger.Information("Shutdown override enabled, skipping shutdown...");
_logger.Information("Shutdown override will be disabled in at most 1 second.");
Task.Run(async () =>
{
await Task.Delay(1000);
App.OverrideShutdown = false;
_logger.Information("Shutdown override disabled.");
});
args.Handled = true;
return;
}

_logger.Debug("JASM shutting down...");
_updateChecker.Dispose();
var tmpDir = new DirectoryInfo(App.TMP_DIR);
Expand Down Expand Up @@ -251,7 +268,8 @@ private void AdminWarningPopup()

private async Task SetLanguage()
{
var selectedLanguage = (await _localSettingsService.ReadOrCreateSettingAsync<AppSettings>(AppSettings.Key)).Language?.ToLower().Trim();
var selectedLanguage = (await _localSettingsService.ReadOrCreateSettingAsync<AppSettings>(AppSettings.Key))
.Language?.ToLower().Trim();
if (selectedLanguage == null)
{
return;
Expand All @@ -261,7 +279,5 @@ private async Task SetLanguage()

if (supportedLanguages.Contains(selectedLanguage))
await App.Localizer.SetLanguage(selectedLanguage);


}
}
Loading