- First Update
This commit is contained in:
266
Mitria_Minecraft_Launcher/LauncherForm.cs
Normal file
266
Mitria_Minecraft_Launcher/LauncherForm.cs
Normal file
@@ -0,0 +1,266 @@
|
||||
using Mitria_Minecraft_Launcher.Updater;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Mitria_Minecraft_Launcher
|
||||
{
|
||||
public partial class LauncherForm : Form
|
||||
{
|
||||
private LoadingScreen _loadingScreen;
|
||||
|
||||
public LauncherForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void LauncherForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
this.Text = ProductName + " v" + ProductVersion;
|
||||
LoadingScreenInitialize();
|
||||
this.textBox_MinecraftPlayerName.Text = Settings.UserLauncherConfig.MinecraftPlayerName;
|
||||
}
|
||||
|
||||
private void LoadingScreenInitialize()
|
||||
{
|
||||
_loadingScreen = new LoadingScreen(Properties.Resources.Loading)
|
||||
{
|
||||
Location = groupBox_MinecraftRun.Location,
|
||||
Size = groupBox_MinecraftRun.Size
|
||||
};
|
||||
_loadingScreen.Visible = false;
|
||||
_loadingScreen.BackColor = Color.FromArgb(220, 220, 220);
|
||||
Controls.Add(_loadingScreen);
|
||||
}
|
||||
|
||||
private void Loading(bool loading)
|
||||
{
|
||||
label_First.Text = "[0/0]";
|
||||
label_Second.Text = "[0/0]";
|
||||
label_First_Percentage.Text = "100%";
|
||||
label_Second_Percentage.Text = "100%";
|
||||
progressBar_First.Value = 0;
|
||||
progressBar_Second.Value = 0;
|
||||
|
||||
if (loading)
|
||||
{
|
||||
_loadingScreen.Visible = true;
|
||||
groupBox_MinecraftRun.Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_loadingScreen.Visible = true;
|
||||
groupBox_MinecraftRun.Visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void button_Setup_Click(object sender, EventArgs e)
|
||||
{
|
||||
LauncherSetupForm launcherSetupForm = new LauncherSetupForm();
|
||||
launcherSetupForm.ShowDialog();
|
||||
}
|
||||
|
||||
private async void button_Run_Click(object sender, EventArgs e)
|
||||
{
|
||||
if(Settings.UserLauncherConfig.GameDirectory == System.Windows.Forms.Application.StartupPath)
|
||||
{
|
||||
MessageBox.Show("The launcher directory and the game directory cannot be the same.", "FATAL Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
textBox_ProgressLog.Text = string.Empty;
|
||||
Loading(true);
|
||||
|
||||
string minecraftPalyerName = this.textBox_MinecraftPlayerName.Text.Trim();
|
||||
if (minecraftPalyerName == string.Empty)
|
||||
{
|
||||
MessageBox.Show("please type Minecraft PlayerName", "FATAL Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
Loading(false);
|
||||
textBox_MinecraftPlayerName.Focus();
|
||||
return;
|
||||
}
|
||||
|
||||
Settings.UserLauncherConfig.MinecraftPlayerName = minecraftPalyerName;
|
||||
var gameProcess = Task.Run(() => GameProcess());
|
||||
bool processResult = await gameProcess;
|
||||
|
||||
if (processResult)
|
||||
{
|
||||
MinecraftRun();
|
||||
}
|
||||
else
|
||||
{
|
||||
Loading(false);
|
||||
}
|
||||
}
|
||||
|
||||
private bool GameProcess()
|
||||
{
|
||||
Updater.GameUpdateManager gameUpdateManager = new Updater.GameUpdateManager();
|
||||
gameUpdateManager.GameUpdateManagerMessage += GameUpdateManager_GameUpdateManagerMessage;
|
||||
GameUpdateStatus updateResult = gameUpdateManager.Start();
|
||||
if (updateResult == GameUpdateStatus.Success)
|
||||
return true;
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void GameUpdateManager_GameUpdateManagerMessage(object sender, Updater.GameUpdateManagerMessageEventArgs e)
|
||||
{
|
||||
switch (e.MessageType)
|
||||
{
|
||||
case Updater.GameUpdateManagerMessageType.First:
|
||||
this.Invoke(new MethodInvoker(
|
||||
delegate ()
|
||||
{
|
||||
textBox_ProgressLog.Text += e.Message + Environment.NewLine;
|
||||
label_First.Text = "[" + e.MinValue.UnitSeparator() + "/" + e.MaxValue.UnitSeparator() + "]";
|
||||
int percent = GetPercent(e.MinValue, e.MaxValue);
|
||||
label_First_Percentage.Text = percent + "%";
|
||||
progressBar_First.Value = percent;
|
||||
|
||||
label_Second.Text = "[0/0]";
|
||||
label_Second_Percentage.Text = "100%";
|
||||
progressBar_Second.Value = 100;
|
||||
}));
|
||||
|
||||
break;
|
||||
|
||||
case Updater.GameUpdateManagerMessageType.Second:
|
||||
this.Invoke(new MethodInvoker(delegate ()
|
||||
{
|
||||
label_Second.Text = "[" + e.MinValue.UnitSeparator() + "/" + e.MaxValue.UnitSeparator() + "]";
|
||||
int percent = GetPercent(e.MinValue, e.MaxValue);
|
||||
label_Second_Percentage.Text = percent + "%";
|
||||
progressBar_Second.Value = percent;
|
||||
}));
|
||||
break;
|
||||
|
||||
case Updater.GameUpdateManagerMessageType.Message:
|
||||
this.Invoke(new MethodInvoker(delegate ()
|
||||
{
|
||||
textBox_ProgressLog.Text += e.Message + Environment.NewLine;
|
||||
}));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private int GetPercent(long minValue, long maxValue)
|
||||
{
|
||||
return (int)((double)minValue / maxValue * 100);
|
||||
}
|
||||
|
||||
private void MinecraftRun()
|
||||
{
|
||||
CommonLibrary.XMLSystem.Save(System.IO.Path.GetFullPath(Settings.UserLauncherConfigPath), Settings.UserLauncherConfig);
|
||||
CommonLibrary.XMLSystem.Save(System.IO.Path.GetFullPath(CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, Settings.UserClientVersionPath)), Settings.UserClientVersion);
|
||||
string runtime = System.IO.Path.GetFullPath(Settings.RuntimeLocation + "\\bin\\javaw.exe");
|
||||
if (!System.IO.File.Exists(runtime))
|
||||
{
|
||||
CommonLibrary.Log.FATAL("not found java");
|
||||
MessageBox.Show("the java could not be found.", "FATAL Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
Loading(false);
|
||||
Settings.UserLauncherConfig.RuntimeVersion = "0.0.0.0"; // 버전초기화
|
||||
return;
|
||||
}
|
||||
string excuteArgumentXml = Settings.UserLauncherConfig.GameDirectory + @"\Mitria\ExcuteArgument.xml";
|
||||
ExcuteArgument excuteArgument = CommonLibrary.XMLSystem.LoadFromPath<ExcuteArgument>(excuteArgumentXml);
|
||||
|
||||
List<Parameter> launcherParameters = new List<Parameter>();
|
||||
launcherParameters.Add(new Parameter("GameDirectory", "\"" + Settings.UserLauncherConfig.GameDirectory + "\""));
|
||||
launcherParameters.Add(new Parameter("argument", Settings.UserLauncherConfig.Argument));
|
||||
launcherParameters.Add(new Parameter("userName", Settings.UserLauncherConfig.MinecraftPlayerName));
|
||||
launcherParameters.Add(new Parameter("uuid", Settings.UserLauncherConfig.MinecraftPlayerName + "uuid"));
|
||||
launcherParameters.Add(new Parameter("accessToken", Settings.UserLauncherConfig.MinecraftPlayerName + "accessToken"));
|
||||
|
||||
excuteArgument.Parameters.AddRange(launcherParameters);
|
||||
|
||||
string argumentsCommand = Extensions.ApplyExcuteCommand(excuteArgument);
|
||||
|
||||
Process process = new Process();
|
||||
ProcessStartInfo processStartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = runtime,
|
||||
CreateNoWindow = true,
|
||||
Arguments = argumentsCommand,
|
||||
UseShellExecute = Settings.UserLauncherConfig.ShellView,
|
||||
WorkingDirectory = Settings.UserLauncherConfig.GameDirectory
|
||||
};
|
||||
|
||||
process.StartInfo = processStartInfo;
|
||||
|
||||
CommonLibrary.Log.INFO("[Minecraft Process] FilName : " + processStartInfo.FileName);
|
||||
CommonLibrary.Log.INFO("[Minecraft Process] CreateNoWindow : " + processStartInfo.CreateNoWindow);
|
||||
CommonLibrary.Log.INFO("[Minecraft Process] Arguments : " + processStartInfo.Arguments);
|
||||
CommonLibrary.Log.INFO("[Minecraft Process] UseShellExecute : " + processStartInfo.UseShellExecute);
|
||||
CommonLibrary.Log.INFO("[Minecraft Process] WorkingDirectory : " + processStartInfo.WorkingDirectory);
|
||||
|
||||
// 크래쉬 확인을 위한 시작시간 저장
|
||||
DateTime criteriaDateTime = DateTime.Now;
|
||||
process.Start();
|
||||
this.Hide();
|
||||
|
||||
process.WaitForExit();
|
||||
process.Close();
|
||||
this.Show();
|
||||
Loading(false);
|
||||
|
||||
string reportPath = ReportCheck(criteriaDateTime);
|
||||
if (reportPath != string.Empty)
|
||||
{
|
||||
string reportText = System.IO.File.ReadAllText(reportPath);
|
||||
ReportView rv = new ReportView(reportText);
|
||||
rv.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void button_Report_Click(object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private string ReportCheck(DateTime criteriaDateTime)
|
||||
{
|
||||
string crashDirectory = CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfigPath, "crash-reports");
|
||||
string lastFileName = string.Empty;
|
||||
if (System.IO.Directory.Exists(crashDirectory))
|
||||
{
|
||||
var reportList = System.IO.Directory.GetFiles(crashDirectory);
|
||||
|
||||
DateTime lastDateTime = criteriaDateTime;
|
||||
foreach (var report in reportList)
|
||||
{
|
||||
FileInfo fi = new FileInfo(report);
|
||||
if (lastDateTime < fi.CreationTime)
|
||||
{
|
||||
lastDateTime = fi.CreationTime;
|
||||
lastFileName = fi.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lastFileName;
|
||||
}
|
||||
|
||||
private void button_Open_LauncherDirectory_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!System.IO.Directory.Exists(System.Windows.Forms.Application.StartupPath))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(System.Windows.Forms.Application.StartupPath);
|
||||
}
|
||||
System.Diagnostics.Process.Start(System.Windows.Forms.Application.StartupPath);
|
||||
}
|
||||
|
||||
private void button_Open_GameDirectory_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!System.IO.Directory.Exists(Settings.UserLauncherConfig.GameDirectory))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(Settings.UserLauncherConfig.GameDirectory);
|
||||
}
|
||||
System.Diagnostics.Process.Start(Settings.UserLauncherConfig.GameDirectory);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user