Skip to content

Commit

Permalink
Release 1.4.20230628.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BuIlDaLiBlE committed Jun 28, 2023
1 parent 40d52de commit 599f23f
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 84 deletions.
2 changes: 1 addition & 1 deletion App.config
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.1.1.3" newVersion="4.1.1.3"/>
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
5 changes: 4 additions & 1 deletion App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Win32;
using Newtonsoft.Json.Linq;
using SevenZip;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -13,7 +14,7 @@ namespace BetterHI3Launcher
{
public partial class App : Application
{
public static readonly LauncherVersion LocalLauncherVersion = new LauncherVersion("1.4.20230329.0");
public static readonly LauncherVersion LocalLauncherVersion = new LauncherVersion("1.4.20230628.0");
public static readonly string LauncherRootPath = AppDomain.CurrentDomain.BaseDirectory;
public static readonly string LocalLowPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}Low";
public static readonly string LauncherDataPath = Path.Combine(LocalLowPath, @"Bp\Better HI3 Launcher");
Expand All @@ -35,6 +36,7 @@ public partial class App : Application
public static readonly int ParallelDownloadSessions = 4;
public static Dictionary<string, string> TextStrings = new Dictionary<string, string>();
public static Mutex Mutex = null;
private static readonly string AssemblyTempPath = Path.GetDirectoryName(typeof(ArchiveFileInfo).Assembly.GetFile("sevenzipsharp.dll").Name);

public App() : base()
{
Expand Down Expand Up @@ -148,6 +150,7 @@ protected override void OnStartup(StartupEventArgs e)
LauncherLanguage = "en";
break;
}
SevenZipBase.SetLibraryPath(Path.Combine(AssemblyTempPath, "7zxa.dll"));
base.OnStartup(e);
}

Expand Down
11 changes: 6 additions & 5 deletions BetterHI3Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Costura64\7zxa.dll" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
Expand Down Expand Up @@ -254,23 +255,23 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Fody">
<Version>6.6.4</Version>
<Version>6.7.0</Version>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="ini-parser">
<Version>2.5.2</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.Platforms">
<Version>7.0.1</Version>
<Version>7.0.3</Version>
</PackageReference>
<PackageReference Include="NETStandard.Library">
<Version>2.0.3</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.3</Version>
</PackageReference>
<PackageReference Include="SharpCompress">
<Version>0.33.0</Version>
<PackageReference Include="Squid-Box.SevenZipSharp">
<Version>1.6.1.23</Version>
</PackageReference>
<PackageReference Include="System.Diagnostics.DiagnosticSource">
<Version>7.0.2</Version>
Expand Down Expand Up @@ -315,7 +316,7 @@
<Version>1.1.1</Version>
</PackageReference>
<PackageReference Include="XamlAnimatedGif">
<Version>2.1.1</Version>
<Version>2.2.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Binary file added Costura64/7zxa.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion DialogWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
<ScrollViewer Name="DialogMessageScrollViewer" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,25" Width="500" Height="135" Focusable="False" ScrollViewer.VerticalScrollBarVisibility="Hidden">
<TextBlock Name="DialogMessage" VerticalAlignment="Center" HorizontalAlignment="Center" MaxWidth="500" MaxHeight="147" Foreground="White" FontFamily="{DynamicResource Font}" FontSize="16" TextAlignment="Center" TextWrapping="Wrap"/>
</ScrollViewer>
<StackPanel Name="InstallStackPanel" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,50,0,0" Visibility="Collapsed">
<StackPanel Name="InstallStackPanel" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,25,0,0" Visibility="Collapsed">
<StackPanel Orientation="Horizontal">
<TextBox Name="InstallPathTextBox" Width="380" Height="20" TextChanged="InstallPathTextBox_TextChanged"/>
<Button Style="{DynamicResource ButtonStyle}" Height="20" Margin="5,0,0,0" FontSize="16" Content="..." Click="BrowseButton_Click"/>
Expand Down
2 changes: 1 addition & 1 deletion FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura />
<Costura IncludeDebugSymbols='false' Unmanaged64Assemblies='sevenzipsharp|7z' />
</Weavers>
60 changes: 37 additions & 23 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.Win32;
using SharpCompress.Archives;
using SharpCompress.Common;
using SharpCompress.Readers;
using Hi3Helper.Http;
using Microsoft.Win32;
using SevenZip;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand All @@ -21,7 +20,6 @@
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shell;
using Hi3Helper.Http;

namespace BetterHI3Launcher
{
Expand Down Expand Up @@ -795,13 +793,9 @@ await Task.Run(() =>
Log("success!", false);
Log("Performing update...");
File.Move(Path.Combine(App.LauncherRootPath, exe_name), Path.Combine(App.LauncherRootPath, old_exe_name));
using(var archive = ArchiveFactory.Open(App.LauncherArchivePath))
using(var archive = new SevenZipExtractor(App.LauncherArchivePath))
{
var reader = archive.ExtractAllEntries();
while(reader.MoveToNextEntry())
{
reader.WriteEntryToDirectory(App.LauncherRootPath, new ExtractionOptions(){ExtractFullPath = true, Overwrite = true, PreserveFileTime = true});
}
archive.ExtractArchive(App.LauncherRootPath);
}
Log("success!", false);
Dispatcher.Invoke(() => {BpUtility.RestartApp();});
Expand Down Expand Up @@ -1017,7 +1011,7 @@ private async void LaunchButton_Click(object sender, RoutedEventArgs e)
{
try
{
var dialog = new DialogWindow(App.TextStrings["msgbox_install_title"], $"{App.TextStrings["msgbox_install_1_msg"]}\n{string.Format(App.TextStrings["msgbox_install_2_msg"], BpUtility.ToBytesCount((long)miHoYoVersionInfo.size))}\n{string.Format(App.TextStrings["msgbox_install_3_msg"], BpUtility.ToBytesCount((long)miHoYoVersionInfo.game.latest.size))}", DialogWindow.DialogType.Install);
var dialog = new DialogWindow(App.TextStrings["msgbox_install_title"], App.TextStrings["msgbox_install_1_msg"], DialogWindow.DialogType.Install);
dialog.InstallPathTextBox.Text = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramW6432%"), GameFullName);
if(dialog.ShowDialog() == false)
{
Expand Down Expand Up @@ -1049,32 +1043,40 @@ private async void LaunchButton_Click(object sender, RoutedEventArgs e)
}
}

var game_install_drive = DriveInfo.GetDrives().Where(x => x.Name == Path.GetPathRoot(GameInstallPath) && x.IsReady).FirstOrDefault();
if(game_install_drive == null || game_install_drive.DriveType == DriveType.CDRom)
{
new DialogWindow(App.TextStrings["msgbox_install_error_title"], App.TextStrings["msgbox_install_wrong_drive_type_msg"]).ShowDialog();
continue;
}

try
{
path = GameInstallPath;
if(!Directory.Exists(GameInstallPath))
{
Directory.CreateDirectory(GameInstallPath);
}
if(new DirectoryInfo(GameInstallPath).Parent == null)
{
throw new Exception("Installation directory cannot be drive root");
}
}
catch(Exception ex)
{
new DialogWindow(App.TextStrings["msgbox_install_dir_error_title"], ex.Message).ShowDialog();
continue;
}

if(new DialogWindow(App.TextStrings["msgbox_install_title"], string.Format(App.TextStrings["msgbox_install_4_msg"], GameInstallPath), DialogWindow.DialogType.Question).ShowDialog() == false)
long free_space_recommended = (long)miHoYoVersionInfo.size + (long)miHoYoVersionInfo.game.latest.size;
string install_message = $"{string.Format(App.TextStrings["msgbox_install_2_msg"], BpUtility.ToBytesCount((long)miHoYoVersionInfo.size))}" +
$"\n{string.Format(App.TextStrings["msgbox_install_3_msg"], BpUtility.ToBytesCount(free_space_recommended), BpUtility.ToBytesCount(game_install_drive.TotalFreeSpace))}" +
$"\n{string.Format(App.TextStrings["msgbox_install_4_msg"], GameInstallPath)}";
if(new DialogWindow(App.TextStrings["msgbox_install_title"], install_message, DialogWindow.DialogType.Question).ShowDialog() == false)
{
try{Directory.Delete(GameInstallPath);}catch{}
continue;
}
var game_install_drive = DriveInfo.GetDrives().Where(x => x.Name == Path.GetPathRoot(GameInstallPath) && x.IsReady).FirstOrDefault();
if(game_install_drive == null || game_install_drive.DriveType == DriveType.CDRom)
{
new DialogWindow(App.TextStrings["msgbox_install_error_title"], App.TextStrings["msgbox_install_wrong_drive_type_msg"]).ShowDialog();
continue;
}
if(game_install_drive.TotalFreeSpace < (long)miHoYoVersionInfo.game.latest.size)
if(game_install_drive.TotalFreeSpace < free_space_recommended)
{
if(new DialogWindow(App.TextStrings["msgbox_install_title"], App.TextStrings["msgbox_install_little_space_msg"], DialogWindow.DialogType.Question).ShowDialog() == false)
{
Expand All @@ -1101,6 +1103,15 @@ private async void LaunchButton_Click(object sender, RoutedEventArgs e)
}
else if(Status == LauncherStatus.UpdateAvailable)
{
if(!File.Exists(GameExePath))
{
if(new DialogWindow(App.TextStrings["msgbox_no_game_exe_title"], App.TextStrings["msgbox_no_game_exe_msg"], DialogWindow.DialogType.Question).ShowDialog() == true)
{
ResetVersionInfo();
GameUpdateCheck();
}
return;
}
var game_install_drive = DriveInfo.GetDrives().Where(x => x.Name == Path.GetPathRoot(GameInstallPath) && x.IsReady).FirstOrDefault();
if(game_install_drive.TotalFreeSpace < (long)miHoYoVersionInfo.game.latest.size)
{
Expand Down Expand Up @@ -1243,11 +1254,14 @@ private async void PreloadButton_Click(object sender, RoutedEventArgs e)
}
if(Directory.GetFiles(GameInstallPath, $"{title}_tmp.*").Length == 0)
{
if(new DialogWindow(App.TextStrings["label_pre_install"], $"{App.TextStrings["msgbox_pre_install_msg"]}\n{string.Format(App.TextStrings["msgbox_install_2_msg"], BpUtility.ToBytesCount(size))}", DialogWindow.DialogType.Question).ShowDialog() == false)
var game_install_drive = DriveInfo.GetDrives().Where(x => x.Name == Path.GetPathRoot(GameInstallPath) && x.IsReady).FirstOrDefault();
string pre_install_message = $"{App.TextStrings["msgbox_pre_install_msg"]}" +
$"\n{string.Format(App.TextStrings["msgbox_install_2_msg"], BpUtility.ToBytesCount(size))}" +
$"\n{string.Format(App.TextStrings["msgbox_install_3_msg"], BpUtility.ToBytesCount((long)miHoYoVersionInfo.game.latest.size), BpUtility.ToBytesCount(game_install_drive.TotalFreeSpace))}";
if(new DialogWindow(App.TextStrings["label_pre_install"], pre_install_message, DialogWindow.DialogType.Question).ShowDialog() == false)
{
return;
}
var game_install_drive = DriveInfo.GetDrives().Where(x => x.Name == Path.GetPathRoot(GameInstallPath) && x.IsReady).FirstOrDefault();
if(game_install_drive.TotalFreeSpace < (long)miHoYoVersionInfo.pre_download_game.latest.size)
{
if(new DialogWindow(App.TextStrings["msgbox_install_title"], App.TextStrings["msgbox_install_little_space_msg"], DialogWindow.DialogType.Question).ShowDialog() == false)
Expand Down
4 changes: 2 additions & 2 deletions Modules/GameCache.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using AssetsTools.NET.Extra;
using Hi3Helper.EncTool;
using Newtonsoft.Json;
using SharpCompress.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Shell;
Expand Down Expand Up @@ -97,7 +97,7 @@ private string CalculateCRC(string path, string hash_salt)
byte[] salt = new mhyEncTool(hash_salt, OnlineVersionInfo.game_info.mirror.mihoyo.master_key.ToString()).GetSalt();
using(FileStream stream = new FileStream(path, FileMode.Open))
{
byte[] hash = new System.Security.Cryptography.HMACSHA1(salt).ComputeHash(stream);
byte[] hash = new HMACSHA1(salt).ComputeHash(stream);
return BitConverter.ToString(hash).Replace("-", string.Empty);
}
}
Expand Down
71 changes: 28 additions & 43 deletions Modules/GameUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
using IniParser.Model;
using Microsoft.Win32;
using Newtonsoft.Json;
using SharpCompress.Archives;
using SharpCompress.Common;
using SharpCompress.Readers;
using SevenZip;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -624,58 +623,44 @@ await Task.Run(() =>
{
return;
}
var skipped_files = new List<string>();
using(var archive = ArchiveFactory.Open(GameArchivePath))
uint skipped_files = 0;
using(var archive = new SevenZipExtractor(GameArchivePath))
{
int unpacked_files = 0;
int file_count = 0;
uint unpacked_count = 0;
uint total_count = archive.FilesCount;
Log("Unpacking game archive...");
Status = LauncherStatus.Unpacking;
foreach(var entry in archive.Entries)
archive.FileExtractionFinished += (sender, args) =>
{
if(!entry.IsDirectory)
double progress = (unpacked_count + 1f) / total_count;
unpacked_count++;
Dispatcher.Invoke(() =>
{
file_count++;
}
DownloadProgressText.Text = string.Format(App.TextStrings["progresstext_unpacking_2"], unpacked_count, total_count, $"{progress * 100:0.00}");
DownloadProgressBar.Value = progress;
TaskbarItemInfo.ProgressValue = progress;
});
};
try
{
archive.ExtractArchive(GameInstallPath);
}
var reader = archive.ExtractAllEntries();
while(reader.MoveToNextEntry())
catch(IOException)
{
try
{
Dispatcher.Invoke(() =>
{
var progress = (unpacked_files + 1f) / file_count;
DownloadProgressText.Text = string.Format(App.TextStrings["progresstext_unpacking_2"], unpacked_files + 1, file_count, Math.Round(progress * 100, 2));
DownloadProgressBar.Value = progress;
TaskbarItemInfo.ProgressValue = progress;
});
reader.WriteEntryToDirectory(GameInstallPath, new ExtractionOptions(){ExtractFullPath = true, Overwrite = true, PreserveFileTime = true});
if(!reader.Entry.IsDirectory)
{
unpacked_files++;
}
}
catch(IOException)
{
throw;
}
catch(Exception ex)
{
if(!reader.Entry.IsDirectory)
{
skipped_files.Add(reader.Entry.ToString());
file_count--;
Log($"Failed to unpack {reader.Entry}: {ex.Message}", true, 1);
}
}
throw;
}
catch(Exception ex)
{
Log($"Failed to unpack file №{unpacked_count + 1}: {ex.Message}", true, 1);
skipped_files++;
total_count--;
}
}
if(skipped_files.Count > 0)
if(skipped_files > 0)
{
DeleteFile(GameArchivePath);
throw new ArchiveException("Game archive is corrupt");
throw new SevenZipArchiveException("Game archive is corrupted, please download again");
}
Log("success!", false);
DeleteFile(GameArchivePath);
Expand Down
2 changes: 1 addition & 1 deletion Modules/LauncherUpdate.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Win32;
using SharpCompress.Common;
using System;
using System.IO;
using System.Security.Cryptography;
using System.Threading;
using System.Windows;
using System.Windows.Shell;
Expand Down
Loading

0 comments on commit 599f23f

Please sign in to comment.