Skip to content

Commit

Permalink
Add local commit
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-nyan committed Apr 25, 2022
1 parent c1c279c commit 0cf4743
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 46 deletions.
2 changes: 1 addition & 1 deletion CollapseLauncher.Updater/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"CollapseLauncher.ReindexPreview": {
"commandName": "Project",
"commandLineArgs": "reindex C:\\myGit\\CollapseLauncher-ReleaseRepo\\preview 1.0.12.0",
"commandLineArgs": "reindex C:\\myGit\\CollapseLauncher-ReleaseRepo\\preview 1.0.13.0",
"nativeDebugging": true
},
"CollapseLauncher.ReindexStable": {
Expand Down
38 changes: 33 additions & 5 deletions CollapseLauncher/Classes/InstallManagement/InstallManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,29 @@ private void ApplyParameter()
CanSkipExtract = File.Exists(Path.Combine(GameDirPath, "@NoExtraction"));
}

public void AddDownloadProperty(string URL, string OutputPath, string OutputDir, string RemoteHash) => DownloadProperty.Add(new DownloadAddressProperty
public void AddDownloadProperty(string URL, string OutputPath, string OutputDir, string RemoteHash, long RemoteRequiredSize) => DownloadProperty.Add(new DownloadAddressProperty
{
URL = URL,
Output = OutputPath,
DirectoryOutput = OutputDir,
RemoteHash = RemoteHash,
RemoteRequiredSize = RemoteRequiredSize
});

public async Task CheckDriveFreeSpace(UIElement Content)
{
DriveInfo _DriveInfo = new DriveInfo(GameDirPath);
long RequiredSpace = DownloadProperty.Sum(x => x.RemoteRequiredSize) - DownloadProperty.Sum(x => GetExistingPartialDownloadLength(x.Output));
long DiskSpace = new DriveInfo(GameDirPath).TotalFreeSpace;

if (DiskSpace < RequiredSpace)
{
await Dialog_InsufficientDriveSpace(Content, DiskSpace, RequiredSpace, _DriveInfo.Name);
throw new IOException($"Free Space on {_DriveInfo.Name} is sufficient! (Free space: {DiskSpace}, Req. Space: {RequiredSpace}, Drive: {_DriveInfo.Name}). Cancelling the task!");
}
}


public void StartDownload()
{
DownloadStopwatch = Stopwatch.StartNew();
Expand Down Expand Up @@ -589,14 +604,25 @@ private void BuildPersistentManifest(in List<PkgVersionProperties> Entries,
// Build data_versions (silence)
ManifestPath = Path.Combine(GameDirPath, $"{ExecutablePrefix}_Data\\Persistent\\silence_data_versions");
ParentURL = $"{QueryProperty.ClientDesignDataSilURL}/AssetBundles";
using (FileStream fs = new FileStream(ManifestPath + "_persist", FileMode.Create, FileAccess.Write))
new HttpClientHelper(false).DownloadFile(ParentURL + "/data_versions", fs, Token);

BuildManifestPersistentList(ManifestPath + "_persist", Entries, ref HashtableManifest, $"{ExecutablePrefix}_Data\\Persistent\\AssetBundles", "", ParentURL);
// Remove read-only and system attribute from silence_data_version that was set by game.
try
{
if (File.Exists(ManifestPath + "_persist"))
{
FileInfo _file = new FileInfo(ManifestPath + "_persist");
_file.IsReadOnly = false;
}
using (FileStream fs = new FileStream(ManifestPath + "_persist", FileMode.Create, FileAccess.Write))
new HttpClientHelper(false).DownloadFile(ParentURL + "/data_versions", fs, Token);

BuildManifestPersistentList(ManifestPath + "_persist", Entries, ref HashtableManifest, $"{ExecutablePrefix}_Data\\Persistent\\AssetBundles", "", ParentURL);
}
catch { }

// Build data_versions
ManifestPath = Path.Combine(GameDirPath, $"{ExecutablePrefix}_Data\\Persistent\\data_versions");
ParentURL = $"{QueryProperty.ClientDesignDataURL}/AssetBundles";
if (File.Exists(ManifestPath + "_persist")) File.Delete(ManifestPath + "_persist");
using (FileStream fs = new FileStream(ManifestPath + "_persist", FileMode.Create, FileAccess.Write))
new HttpClientHelper(false).DownloadFile(ParentURL + "/data_versions", fs, Token);

Expand All @@ -606,6 +632,7 @@ private void BuildPersistentManifest(in List<PkgVersionProperties> Entries,
ManifestPath = Path.Combine(GameDirPath, $"{ExecutablePrefix}_Data\\Persistent\\res_versions");
ParentURL = $"{QueryProperty.ClientGameResURL}/StandaloneWindows64";
ParentAudioURL = $"{QueryProperty.ClientAudioAssetsURL}/StandaloneWindows64";
if (File.Exists(ManifestPath + "_persist")) File.Delete(ManifestPath + "_persist");
using (FileStream fs = new FileStream(ManifestPath + "_persist", FileMode.Create, FileAccess.Write))
new HttpClientHelper(false).DownloadFile(ParentURL + "/release_res_versions_external", fs, Token);

Expand Down Expand Up @@ -820,6 +847,7 @@ public class DownloadAddressProperty
public string Output;
public string DirectoryOutput;
public long RemoteSize;
public long RemoteRequiredSize;
public long LocalSize;
public long LocalUncompressedSize;
public bool IsCorrupted = false;
Expand Down
2 changes: 1 addition & 1 deletion CollapseLauncher/CollapseLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
<WindowsPackageType>None</WindowsPackageType>
<IncludeGetResolvedSDKReferences>true</IncludeGetResolvedSDKReferences>
<Version>1.0.12.0</Version>
<Version>1.0.13.0</Version>
<Configurations>Debug;Release;Publish</Configurations>
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>
Expand Down
48 changes: 45 additions & 3 deletions CollapseLauncher/Pages/Dialogs/SimpleDialogs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;

using Microsoft.UI.Xaml;
Expand Down Expand Up @@ -67,6 +69,33 @@ await SpawnDialog(
null
);

public static async Task<int> Dialog_ChooseAudioLanguage(UIElement Content, List<string> langlist)
{
// Default: 2 (Japanese)
int index = 2;
StackPanel Panel = new StackPanel();
ComboBox LangBox = new ComboBox()
{
PlaceholderText = "Select your Audio Language",
Width = 256,
ItemsSource = langlist,
SelectedIndex = index,
HorizontalAlignment = HorizontalAlignment.Center,
};
Panel.Children.Add(new TextBlock()
{
Text = $"Before you install the game, you need to choose which audio language you want to use (Default: Japanese):",
TextWrapping = TextWrapping.Wrap,
Margin = new Thickness(0,0,0,16)
});
Panel.Children.Add(LangBox);
await SpawnDialog("Choose Audio Language", Panel, Content, null, "Next", null);

index = LangBox.SelectedIndex;

return index;
}

public static async Task<ContentDialogResult> Dialog_AdditionalDownloadNeeded(UIElement Content, long fileSize) =>
await SpawnDialog(
"Additional Download is Needed",
Expand Down Expand Up @@ -241,14 +270,27 @@ public static async Task<ContentDialogResult> Dialog_ExistingDownload(UIElement
await SpawnDialog(
"Resume Download?",
string.Format("You have downloaded {0}/{1} of the game previously.\r\n\r\nDo you want to continue?",
ConverterTool.SummarizeSizeSimple(partialLength),
ConverterTool.SummarizeSizeSimple(contentLength)),
SummarizeSizeSimple(partialLength),
SummarizeSizeSimple(contentLength)),
Content,
null,
"Yes, Resume",
"No, Start from Beginning"
);

public static async Task<ContentDialogResult> Dialog_InsufficientDriveSpace(UIElement Content, long DriveFreeSpace, long RequiredSpace, string DriveLetter) =>
await SpawnDialog(
"Disk space is insufficient",
string.Format("You don't have enough free space to install this game on your {2} drive!\r\n\r\nFree Space: {0}\r\nRequired Space: {1}.\r\n\r\nPlease make sure you have enough disk space before installing.",
SummarizeSizeSimple(DriveFreeSpace),
SummarizeSizeSimple(RequiredSpace),
DriveLetter),
Content,
null,
"Okay",
null
);

public static async Task<ContentDialogResult> Dialog_RelocateFolder(UIElement Content) =>
await SpawnDialog(
"Relocate App Data Folder",
Expand Down Expand Up @@ -284,7 +326,7 @@ await SpawnDialog(
);

public static async Task<ContentDialogResult> SpawnDialog(
string title, string content, UIElement Content,
string title, object content, UIElement Content,
string closeText = null, string primaryText = null,
string secondaryText = null, ContentDialogButton defaultButton = ContentDialogButton.Primary) =>
await new ContentDialog
Expand Down
3 changes: 3 additions & 0 deletions CollapseLauncher/Pages/HomePage.Variable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ public struct AdditionalFile
string GameZipPath;
string GameZipRemoteHash;
string GameZipLocalHash;
long GameZipSize;
long GameZipRequiredSize;

string GameZipVoiceUrl;
string GameZipVoicePath;
string GameZipVoiceRemoteHash;
long GameZipVoiceSize;
long GameZipVoiceRequiredSize;

RegionResourceVersion VoicePackFile = new RegionResourceVersion();
InstallManagement InstallTool;
Expand Down
102 changes: 75 additions & 27 deletions CollapseLauncher/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ private async void InstallGameDialog(object sender, RoutedEventArgs e)
}
MainFrameChanger.ChangeMainFrame(typeof(HomePage));
}
catch (IOException ex)
{
LogWriteLine($"Installation cancelled for region {CurrentRegion.ZoneName} because of IO Error!\r\n{ex}", Hi3Helper.LogType.Warning, true);
MainFrameChanger.ChangeMainFrame(typeof(HomePage));
}
catch (TaskCanceledException)
{
LogWriteLine($"Installation cancelled for region {CurrentRegion.ZoneName}");
Expand Down Expand Up @@ -385,14 +390,17 @@ private async Task StartInstallationProcedure(string destinationFolder)
if (string.IsNullOrEmpty(GameDirPath))
throw new OperationCanceledException();

TryAddVoicePack(GetUpdateDiffs());
// await TryAddVoicePack(GetUpdateDiffs());
await TrySetVoicePack(GetUpdateDiffs());
CurrentRegion.SetVoiceLanguageID(VoicePackFile.languageID ?? 2);

if (IsGameHasVoicePack)
{
GameZipVoiceUrl = VoicePackFile.path;
GameZipVoicePath = Path.Combine(GameDirPath, Path.GetFileName(GameZipVoiceUrl));
GameZipVoiceRemoteHash = VoicePackFile.md5.ToLower();
GameZipVoiceSize = VoicePackFile.package_size;
GameZipVoiceRequiredSize = VoicePackFile.size;
}

while (!await DownloadGameClient(GameDirPath))
Expand Down Expand Up @@ -425,23 +433,8 @@ private void ApplyGameConfig(string destinationFolder)
gameIni.Profile["launcher"]["game_install_path"] = destinationFolder.Replace('\\', '/');
SaveGameProfile();
PrepareGameConfig();
// GamePkgVersionVerification();
}

private void GamePkgVersionVerification()
{
string GamePath = NormalizePath(gameIni.Profile["launcher"]["game_install_path"].ToString());
string PkgVersionPath = Path.Combine(GamePath, "pkg_version");

string[] PkgVersionData = File.ReadAllLines(PkgVersionPath);
int PkgVersionDataCount = PkgVersionData.Length - 1;

PkgVersionProperties pkgVersionProperties;

for (int i = 0; i < PkgVersionDataCount; i++)
{
pkgVersionProperties = JsonConvert.DeserializeObject<PkgVersionProperties>(PkgVersionData[i]);
}
if (IsGameHasVoicePack && (CurrentRegion.IsGenshin ?? false))
CurrentRegion.SetVoiceLanguageID(VoicePackFile.languageID ?? 2);
}

/*
Expand Down Expand Up @@ -522,6 +515,7 @@ private async Task<bool> DownloadGameClient(string destinationFolder)
GameZipUrl = regionResourceProp.data.game.latest.path;
GameZipRemoteHash = regionResourceProp.data.game.latest.md5.ToLower();
GameZipPath = Path.Combine(destinationFolder, Path.GetFileName(GameZipUrl));
GameZipRequiredSize = regionResourceProp.data.game.latest.size;

DispatcherQueue.TryEnqueue(() =>
{
Expand Down Expand Up @@ -549,9 +543,9 @@ private async Task<bool> DownloadGameClient(string destinationFolder)
CurrentRegion.GetRegServerNameID(),
Path.GetFileNameWithoutExtension(CurrentRegion.GameExecutableName));

InstallTool.AddDownloadProperty(GameZipUrl, GameZipPath, GameDirPath, GameZipRemoteHash);
InstallTool.AddDownloadProperty(GameZipUrl, GameZipPath, GameDirPath, GameZipRemoteHash, GameZipRequiredSize);
if (IsGameHasVoicePack)
InstallTool.AddDownloadProperty(GameZipVoiceUrl, GameZipVoicePath, GameDirPath, GameZipVoiceRemoteHash);
InstallTool.AddDownloadProperty(GameZipVoiceUrl, GameZipVoicePath, GameDirPath, GameZipVoiceRemoteHash, GameZipVoiceRequiredSize);

ProgressStatusGrid.Visibility = Visibility.Visible;
UpdateGameBtn.Visibility = Visibility.Collapsed;
Expand All @@ -561,6 +555,7 @@ private async Task<bool> DownloadGameClient(string destinationFolder)
InstallTool.InstallProgressChanged += InstallToolProgress;
bool RetryRoutine = true;

await InstallTool.CheckDriveFreeSpace(Content);
await InstallTool.CheckExistingDownloadAsync(Content);

while (RetryRoutine)
Expand Down Expand Up @@ -1287,17 +1282,20 @@ private async void UpdateGameDialog(object sender, RoutedEventArgs e)
GameZipUrl = diff.path;
GameZipRemoteHash = diff.md5.ToLower();
GameZipPath = Path.Combine(GameDirPath, Path.GetFileName(GameZipUrl));
InstallTool.AddDownloadProperty(GameZipUrl, GameZipPath, GameDirPath, GameZipRemoteHash);
GameZipRequiredSize = diff.size;

TryAddVoicePack(GetUpdateDiffs(false));
InstallTool.AddDownloadProperty(GameZipUrl, GameZipPath, GameDirPath, GameZipRemoteHash, GameZipRequiredSize);

await TryAddVoicePack(GetUpdateDiffs(false));

if (IsGameHasVoicePack)
{
GameZipVoiceUrl = VoicePackFile.path;
GameZipVoiceRemoteHash = VoicePackFile.md5;
GameZipVoicePath = Path.Combine(GameDirPath, Path.GetFileName(GameZipVoiceUrl));
GameZipVoiceSize = VoicePackFile.package_size;
InstallTool.AddDownloadProperty(GameZipVoiceUrl, GameZipVoicePath, GameDirPath, GameZipVoiceRemoteHash);
GameZipVoiceRequiredSize = VoicePackFile.size;
InstallTool.AddDownloadProperty(GameZipVoiceUrl, GameZipVoicePath, GameDirPath, GameZipVoiceRemoteHash, GameZipVoiceRequiredSize);
}

try
Expand All @@ -1310,6 +1308,7 @@ private async void UpdateGameDialog(object sender, RoutedEventArgs e)
InstallTool.InstallProgressChanged += InstallToolProgress;
bool RetryRoutine = true;

await InstallTool.CheckDriveFreeSpace(Content);
await InstallTool.CheckExistingDownloadAsync(Content);

while (RetryRoutine)
Expand All @@ -1323,7 +1322,12 @@ private async void UpdateGameDialog(object sender, RoutedEventArgs e)

ApplyGameConfig(GameDirPath);
MainFrameChanger.ChangeMainFrame(typeof(HomePage));
OverlapFrame.Navigate(typeof(HomePage), null, new DrillInNavigationTransitionInfo());
// OverlapFrame.Navigate(typeof(HomePage), null, new DrillInNavigationTransitionInfo());
}
catch (IOException ex)
{
MainFrameChanger.ChangeMainFrame(typeof(HomePage));
LogWriteLine($"Update cancelled because of IO Error!\r\n{ex}", Hi3Helper.LogType.Warning);
}
catch (OperationCanceledException)
{
Expand Down Expand Up @@ -1684,19 +1688,63 @@ public void ApplyDeltaPatch(string GamePath)
File.Delete(patchListPath);
}

private void TryAddVoicePack(in RegionResourceVersion diffVer)
private async Task TryAddVoicePack(RegionResourceVersion diffVer)
{
int langID;
if (diffVer.voice_packs != null
&& diffVer.voice_packs.Count > 0)
{
IsGameHasVoicePack = true;
VoicePackFile = diffVer.voice_packs[langID = CurrentRegion.GetVoiceLanguageID()];
VoicePackFile.languageID = langID;
return;
}
LogWriteLine($"This {CurrentRegion.ProfileName} region doesn't have Voice Pack");
IsGameHasVoicePack = false;
}

private async Task TrySetVoicePack(RegionResourceVersion diffVer)
{
int langID;
if (diffVer.voice_packs != null
&& diffVer.voice_packs.Count > 0)
{
IsGameHasVoicePack = true;
VoicePackFile = diffVer.voice_packs[CurrentRegion.GetVoiceLanguageID()];
VoicePackFile = diffVer.voice_packs[langID = await Dialog_ChooseAudioLanguage(Content, EnumerateAudioLanguageString(diffVer))];
VoicePackFile.languageID = langID;
return;
}
LogWriteLine($"This {CurrentRegion.ProfileName} region doesn't have Voice Pack");
IsGameHasVoicePack = false;
}

private List<string> EnumerateAudioLanguageString(RegionResourceVersion diffVer)
{
List<string> value = new List<string>();
foreach (RegionResourceVersion Entry in diffVer.voice_packs)
{
switch (Entry.language)
{
case "en-us":
value.Add("English (US)");
break;
case "ja-jp":
value.Add("Japanese");
break;
case "zh-cn":
value.Add("Chinese (Simplified)");
break;
case "ko-kr":
value.Add("Korean");
break;
default:
value.Add(Entry.language);
break;
}
}
return value;
}

private async void PredownloadDialog(object sender, RoutedEventArgs e)
{
PauseDownloadPreBtn.Visibility = Visibility.Visible;
Expand All @@ -1708,7 +1756,7 @@ private async void PredownloadDialog(object sender, RoutedEventArgs e)
GameZipUrl = diffVer.path;
GameZipRemoteHash = diffVer.md5.ToLower();

TryAddVoicePack(diffVer);
await TryAddVoicePack(diffVer);

if (IsGameHasVoicePack)
{
Expand Down
Loading

0 comments on commit 0cf4743

Please sign in to comment.