Exemplo n.º 1
0
        private static void Main()
        {
            Console.Title = @"Comet";

            ConsoleManager.DrawLine();
            Console.WriteLine(@"Comet Installer");

            try
            {
                _resourceSettings = new ResourceSettings();
                TerminateRunningProcess(_resourceSettings);
                Installer.InstallData(_resourceSettings);

                if (_resourceSettings.RestartApplicationAfterInstall)
                {
                    StartExecutable(_resourceSettings.ExecutablePath);
                }
                else
                {
                    // TODO: Exit
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadLine();
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Loads the resource settings.
        /// </summary>
        public void LoadSettings()
        {
            try
            {
                ConsoleManager.DrawLine();
                Console.WriteLine(@"Loading settings...");
                ConsoleManager.DrawLine();

                _logging          = LoadInstallerSetting <bool>("Logging");
                _executablePath   = LoadInstallerSetting <string>("ExecutablePath");
                _installDirectory = LoadInstallerSetting <string>("InstallDirectory");
                _productName      = LoadInstallerSetting <string>("ProductName");
                _restartApplicationAfterInstall = LoadInstallerSetting <bool>("RestartApplicationAfterInstall");

                ConsoleManager.DrawLine();
                Console.WriteLine(@"Initializing");
                ConsoleManager.DrawLine();

                _workingFolder = Path.GetTempPath() + _productName + @"\Updater\";
                Console.WriteLine(@"Working Folder: " + _workingFolder);
                ConsoleManager.DrawLine();

                _downloadFolder     = _workingFolder + @"Download\";
                _installFilesFolder = _workingFolder + @"InstallFiles\";
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Terminate the running process.
        /// </summary>
        /// <param name="resourceSettings">The resource settings.</param>
        private static void TerminateRunningProcess(ResourceSettings resourceSettings)
        {
            string _processName = Path.GetFileNameWithoutExtension(resourceSettings.ExecutablePath);

            foreach (Process _process in Process.GetProcesses())
            {
                if (_process.ProcessName == _processName)
                {
                    Console.WriteLine(@"Terminating process: " + _processName);
                    ConsoleManager.DrawLine();
                    _process.Kill();
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>Cleanup the temporary install files.</summary>
        /// <param name="resourceSettings">The resource Settings.</param>
        public static void Cleanup(ResourceSettings resourceSettings)
        {
            Console.WriteLine(@"Cleaning up...");
            ConsoleManager.DrawLine();

            if (Directory.Exists(resourceSettings.DownloadFolder))
            {
                Directory.Delete(resourceSettings.DownloadFolder, true);
            }

            if (Directory.Exists(resourceSettings.InstallFilesFolder))
            {
                Directory.Delete(resourceSettings.InstallFilesFolder, true);
            }
        }
Exemplo n.º 5
0
        /// <summary>Start the executable application.</summary>
        /// <param name="filename">The filename.</param>
        /// <param name="processWindowStyle">The process window style.</param>
        private static void StartExecutable(string filename, ProcessWindowStyle processWindowStyle = ProcessWindowStyle.Normal)
        {
            Process _process = new Process
            {
                StartInfo =
                {
                    FileName    = filename,
                    WindowStyle = processWindowStyle
                }
            };

            Console.WriteLine(@"Starting process ({0}): {1}", processWindowStyle.ToString(), filename);
            ConsoleManager.DrawLine();
            _process.Start();
        }
Exemplo n.º 6
0
        /// <summary>Install the data.</summary>
        /// <param name="resourceSettings">The resource Settings.</param>
        public static void InstallData(ResourceSettings resourceSettings)
        {
            Console.WriteLine(@"Installing...");
            ConsoleManager.DrawLine();

            foreach (string _file in Directory.GetFiles(resourceSettings.InstallFilesFolder, "*.*", SearchOption.AllDirectories))
            {
                string _destination = _file.Replace(resourceSettings.InstallFilesFolder, resourceSettings.InstallDirectory);

                Console.WriteLine(@"Copying file: " + _file);
                Console.WriteLine(@"To: " + _destination);
                ConsoleManager.DrawLine();
                File.Copy(_file, _destination, true);
            }

            Cleanup(resourceSettings);
        }