Skip to content

Commit

Permalink
占用别太离谱了😨
Browse files Browse the repository at this point in the history
  • Loading branch information
Waheal committed Jul 13, 2024
1 parent b3e2e88 commit 1b6a191
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
6 changes: 3 additions & 3 deletions MSL/controls/dialogs/DownloadDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void Downloader()
{
downloadOpt.RequestConfiguration.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36";
}
downloadOpt.Timeout = 10000;
downloadOpt.Timeout = 5000;
downloadOpt.ChunkCount = downloadthread; // file parts to download, default value is 1
downloadOpt.ParallelDownload = true; // download parts of file as parallel or not. Default value is false
downloader = new DownloadService(downloadOpt);
Expand Down Expand Up @@ -115,7 +115,7 @@ private void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
updateUITimer.Stop();
}
catch { }
catch { Console.WriteLine("Stop UITimer Failed"); }
if (_dialogReturn == 2)
{
Dispatcher.Invoke(() =>
Expand All @@ -125,7 +125,7 @@ private void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
File.Delete(downloadPath + "\\" + filename);
}
catch { }
catch { Console.WriteLine("Delete File Failed"); }
});
}
else
Expand Down
32 changes: 28 additions & 4 deletions MSL/controls/dialogs/InstallForgeDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ICSharpCode.SharpZipLib.Zip;
using Microsoft.Extensions.Logging.Abstractions;
using MSL.utils;
using Newtonsoft.Json.Linq;
using System;
Expand Down Expand Up @@ -32,12 +33,12 @@ public partial class InstallForgeDialog
private readonly string tempPath;
private readonly string libPath;
private readonly string javaPath;
private StreamWriter logWriter;
private int versionType; //由于Forge安装器的json有4种格式(太6了),在此进行规定:①1.20.3-Latest ②?-1.20.2

public InstallForgeDialog(string forge, string downPath, string java)
{
InitializeComponent();
Log_in("准备开始安装Forge···");
forgePath = forge;//传递路径过来
installPath = downPath;
tempPath = downPath + "/temp";
Expand All @@ -48,6 +49,9 @@ public InstallForgeDialog(string forge, string downPath, string java)
private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
File.Create(installPath + "/msl-installForge.log").Close();
logWriter = File.AppendText(installPath + "/msl-installForge.log");
Log_in("准备开始安装Forge···");
Task.Run(Install);
}

Expand Down Expand Up @@ -462,31 +466,38 @@ await Dispatcher.Invoke(async () =>
}
}
//输出日志
/*
Dispatcher.Invoke(() =>
{
File.WriteAllText(installPath + "/msl-installForge.log", log.Text);
});
*/

Log_in("安装结束!");
Status_change("结束!本对话框将自动关闭!");
try
{
//File.Delete(installPath + "/install.bat");
logWriter.Flush();
logWriter.Close();
logWriter.Dispose();
Directory.Delete(tempPath, true);
}
catch// (Exception ex)
catch(Exception ex)
{
//没log
Console.WriteLine(ex.Message);
}
Thread.Sleep(1500);
_dialogReturn = 1;
Dispatcher.Invoke(() =>
{
log.Clear();
CloseDialog();
});
}
catch (OperationCanceledException) { return; }
}

private string logTemp = "";
private int counter = 100;
private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
Expand All @@ -499,7 +510,7 @@ private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
Log_in(logTemp);
logTemp = "";
}
logTemp = logTemp + e.Data + "\n";
logTemp += e.Data + "\n";
counter++;
}
}
Expand All @@ -509,9 +520,22 @@ private void Log_in(string logStr)
cancellationTokenSource.Token.ThrowIfCancellationRequested();
Dispatcher.Invoke(() =>
{
if (log.LineCount > 150)
{
log.Clear();
}
log.Text += logStr + "\n";
log.ScrollToEnd();
});
try
{
// 写入日志文件
logWriter.WriteLineAsync(logStr);
}
catch
{
Console.WriteLine("Write log failed!");
}
}

private void Status_change(string textStr)
Expand Down

0 comments on commit 1b6a191

Please sign in to comment.