Skip to content

Commit

Permalink
Merge pull request #85 from DawnFz/development
Browse files Browse the repository at this point in the history
合并 Development 分支
  • Loading branch information
DawnFz authored Nov 1, 2022
2 parents e179233 + e1a54f0 commit 7e3fa8e
Show file tree
Hide file tree
Showing 12 changed files with 329 additions and 265 deletions.
3 changes: 2 additions & 1 deletion GenShin_Launcher_Plus/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public partial class App : Application
public App()
{
LoadProgramCore = new();
DataModel = new();
InitializeComponent();
}

Expand All @@ -30,7 +31,7 @@ protected override void OnStartup(StartupEventArgs e)
/// <summary>
/// 用于检查程序是否运行在游戏目录
/// </summary>
private void RunPathCheck()
private static void RunPathCheck()
{
if (File.Exists(@"YuanShen.exe") &&
Directory.Exists(@"YuanShen_Data") ||
Expand Down
1 change: 0 additions & 1 deletion GenShin_Launcher_Plus/Core/LoadProgramCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class LoadProgramCore
{
public LoadProgramCore()
{
App.Current.DataModel = new();
App.Current.NoticeOverAllBase = new();
}

Expand Down
2 changes: 1 addition & 1 deletion GenShin_Launcher_Plus/GenShin_Launcher_Plus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<Version>1.5.3.0</Version>
<Version>1.5.4.0</Version>
<StartupObject>GenShin_Launcher_Plus.App</StartupObject>
<ApplicationIcon>ICON.ico</ApplicationIcon>
<IsPublishable>True</IsPublishable>
Expand Down
32 changes: 14 additions & 18 deletions GenShin_Launcher_Plus/Helper/DownloadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,22 @@ public async Task DownloadHttpFileAsync(string url, string fileName)
}
DownloadBarMax = (double)response.Content.Headers.ContentLength;

using (Stream responseStream = await response.Content.ReadAsStreamAsync())
using Stream responseStream = await response.Content.ReadAsStreamAsync();
int bufferSize = 2048;
using FileStream fileStream = new(fileName, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize, true);
byte[] buffer = new byte[bufferSize];
long progressBarValue = 0;
int bytesRead = 0;
do
{
int bufferSize = 2048;
using (FileStream fileStream = new(fileName, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize, true))
{
byte[] buffer = new byte[bufferSize];
long progressBarValue = 0;
int bytesRead = 0;
do
{
bytesRead = await responseStream.ReadAsync(buffer, 0, buffer.Length);
await fileStream.WriteAsync(buffer, 0, bytesRead);
progressBarValue += bytesRead;
DownloadBarValue = progressBarValue;
//fire and forget
SetProgressBar();
}
while (bytesRead > 0);
}
bytesRead = await responseStream.ReadAsync(buffer, 0, buffer.Length);
await fileStream.WriteAsync(buffer, 0, bytesRead);
progressBarValue += bytesRead;
DownloadBarValue = progressBarValue;
//fire and forget
SetProgressBar();
}
while (bytesRead > 0);
}

/// <summary>
Expand Down
35 changes: 11 additions & 24 deletions GenShin_Launcher_Plus/Helper/IniParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public IniParser(string iniPath)
TextReader iniFile = null;
string strLine = null;
string currentRoot = null;
string[] keyPair = null;
iniFilePath = iniPath;
if (File.Exists(iniPath))
{
Expand All @@ -40,11 +39,10 @@ public IniParser(string iniPath)
}
else
{
keyPair = strLine.Split(new char[] { '=' }, 2);
string[] keyPair = strLine.Split(new char[] { '=' }, 2);
SectionPair sectionPair;
string value = null;
if (currentRoot == null)
currentRoot = "ROOT";
currentRoot ??= "ROOT";
sectionPair.Section = currentRoot;
sectionPair.Key = keyPair[0];
if (keyPair.Length > 1)
Expand All @@ -55,10 +53,7 @@ public IniParser(string iniPath)
strLine = iniFile.ReadLine();
}
}
catch (Exception ex)
{
MessageBox.Show($"Error : {ex.Message}");
}
catch { }
finally
{
if (iniFile != null)
Expand All @@ -77,21 +72,17 @@ public IniParser(string iniPath)
/// <summary>
/// 根据类型返回相应内容
/// </summary>
public string GetSetting(string sectionName, string settingName, int i=0)
public string GetSetting(string sectionName, string settingName, int i = 0)
{
SectionPair sectionPair;
sectionPair.Section = sectionName;
sectionPair.Key = settingName;
switch (i)
return i switch
{
case 1:
return (string)keyPairs[sectionPair] != string.Empty ? (string)keyPairs[sectionPair] : "1";
case 2:
return (string)keyPairs[sectionPair] != string.Empty ? (string)keyPairs[sectionPair] : "False";
default:
return (string)keyPairs[sectionPair];
}

1 => (string)keyPairs[sectionPair] != string.Empty ? (string)keyPairs[sectionPair] : "1",
2 => (string)keyPairs[sectionPair] != string.Empty ? (string)keyPairs[sectionPair] : "False",
_ => (string)keyPairs[sectionPair],
};
}

public void AddSetting(string sectionName, string settingName, string settingValue)
Expand All @@ -107,7 +98,6 @@ public void AddSetting(string sectionName, string settingName, string settingVal
public void SaveSettings()
{
ArrayList sections = new();
string tmpValue = "";
string strToSave = "";
foreach (SectionPair sectionPair in keyPairs.Keys)
{
Expand All @@ -121,7 +111,7 @@ public void SaveSettings()
{
if (sectionPair.Section == section)
{
tmpValue = (string)keyPairs[sectionPair];
string tmpValue = (string)keyPairs[sectionPair];
if (tmpValue != null)
tmpValue = "=" + tmpValue;
strToSave += (sectionPair.Key + tmpValue + "\r\n");
Expand All @@ -135,10 +125,7 @@ public void SaveSettings()
tw.Write(strToSave);
tw.Close();
}
catch (Exception ex)
{
MessageBox.Show($"Error : {ex.Message}");
}
catch { }
}
}
}
2 changes: 0 additions & 2 deletions GenShin_Launcher_Plus/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public MainWindow()
MainSizeBinding();
MainFlipView.DataContext = App.Current.NoticeOverAllBase;
HomePage.Children.Add(new Views.HomePage());
Height = Convert.ToDouble(App.Current.DataModel.MainHeight);
Width = Convert.ToDouble(App.Current.DataModel.MainWidth);
}

private void WindowDragMove(object sender, MouseButtonEventArgs e)
Expand Down
Loading

0 comments on commit 7e3fa8e

Please sign in to comment.