149 lines
5.2 KiB
C#
149 lines
5.2 KiB
C#
using SuperMap.RealEstate.Launcher_WinForm;
|
|
using System;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
|
|
namespace SuperMap.RealEstate.Launcher
|
|
{
|
|
static class Program
|
|
{
|
|
/// <summary>
|
|
/// 应用程序的主入口点。
|
|
/// </summary>
|
|
[STAThread]
|
|
static void Main(string[] args)
|
|
{
|
|
Application.EnableVisualStyles();
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
#if DEBUG
|
|
args = new string[1];
|
|
args[0] = "smre://AppRuns/4FF62E0BDA7B264BDBCE1352EC311BED5816469B49921581/6BBE7A06EA9145F5/68AE6B5DD7AAC86C/341144E287123182456363CCB66025B5304AF28D94EF902A7470E2966E71DC348A9BD6DFC642307340FAEB06EAA6BC54BCA73A43DDC6C2EF/";
|
|
//args[0] = "smre://Install/4FF62E0BDA7B264BDBCE1352EC311BED5816469B49921581////";
|
|
//MessageBox.Show(args[0].Length.ToString());
|
|
#endif
|
|
try
|
|
{
|
|
if (args.Length == 0)
|
|
{
|
|
if (Application.ExecutablePath.EndsWith(LaunchHelper.Launcher_UpdateFileName))
|
|
Run_Update();
|
|
else
|
|
Run_Register();
|
|
}
|
|
else if (args.Length == 1)
|
|
{
|
|
if (Application.ExecutablePath.EndsWith(LaunchHelper.Launcher_UpdateFileName))
|
|
Run_Update(new LauncherInfo(args[0]));
|
|
else
|
|
Run_Open(new LauncherInfo(args[0]));
|
|
}
|
|
else
|
|
Run_Error();
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
Run_Error(ex);
|
|
}
|
|
}
|
|
|
|
#region Run_Error
|
|
private static void Run_Error(Exception ex = null)
|
|
{
|
|
string _Message = "错误的参数!";
|
|
if (ex != null)
|
|
_Message = ex.Message;
|
|
LoadingHelper.ForceExit();
|
|
MessageBox.Show(_Message, "驿商科技", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
#endregion
|
|
|
|
#region Run_Register
|
|
private static void Run_Register()
|
|
{
|
|
Application.Run(new frmRegister());
|
|
DeleteUpdateFile();
|
|
}
|
|
#endregion
|
|
|
|
#region Run_Update
|
|
private static void Run_Update(LauncherInfo launcherInfo = null)
|
|
{
|
|
string _Launcher_FileName = AppDomain.CurrentDomain.BaseDirectory + LaunchHelper.Launcher_FileName;
|
|
int _ErrorCount = 10;
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
File.Copy(Application.ExecutablePath, _Launcher_FileName, true);
|
|
break;
|
|
}
|
|
catch
|
|
{
|
|
if (_ErrorCount >= 0)
|
|
{
|
|
System.Threading.Thread.Sleep(1000);
|
|
_ErrorCount--;
|
|
continue;
|
|
}
|
|
if (MessageBox.Show("无法替换文件,请确认程序已关闭!", "驿商科技", MessageBoxButtons.RetryCancel,
|
|
MessageBoxIcon.Warning) == DialogResult.Retry)
|
|
continue;
|
|
else
|
|
return;
|
|
}
|
|
}
|
|
if (launcherInfo != null)
|
|
launcherInfo.ProcessRestart();
|
|
}
|
|
#endregion
|
|
|
|
#region Run_Open
|
|
private static void Run_Open(LauncherInfo launcherInfo)
|
|
{
|
|
WriteResouceFile();
|
|
if (launcherInfo.Type.Equals("AppRuns", StringComparison.CurrentCultureIgnoreCase))
|
|
{
|
|
LauncherApplication _LauncherAppRuns = new LauncherApplication(launcherInfo);
|
|
_LauncherAppRuns.AppRuns();
|
|
_LauncherAppRuns.Close();
|
|
}
|
|
else if (launcherInfo.Type.Equals("Install", StringComparison.CurrentCultureIgnoreCase))
|
|
{
|
|
LauncherApplication _LauncherInstall = new LauncherApplication(launcherInfo);
|
|
_LauncherInstall.Installer();
|
|
_LauncherInstall.Close();
|
|
}
|
|
else
|
|
MessageBox.Show(launcherInfo.Type + "暂不支持!");
|
|
DeleteUpdateFile();
|
|
}
|
|
#endregion
|
|
|
|
#region WriteResouceFile
|
|
static void WriteResouceFile()
|
|
{
|
|
string[] _ResourcColleection = { "Launcher.Register.exe", "Launcher.Loading.exe" };
|
|
foreach (string _ResouceName in _ResourcColleection)
|
|
{
|
|
if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "Bin\\" + _ResouceName))
|
|
frmRegister.WriteResouceFile(AppDomain.CurrentDomain.BaseDirectory + "Bin\\", _ResouceName);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region DeleteUpdateFile
|
|
private static void DeleteUpdateFile()
|
|
{
|
|
try
|
|
{
|
|
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + LaunchHelper.Launcher_UpdateFileName))
|
|
File.Delete(AppDomain.CurrentDomain.BaseDirectory + LaunchHelper.Launcher_UpdateFileName);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|