Пример #1
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Set an error handler (just a message box) for unexpected exceptions in threads
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            // Parse command line arguments
            CommandlineArguments arguments = new CommandlineArguments(args);

            // Is a database path set per command line?
            if (!string.IsNullOrEmpty(arguments["database"]))
            {
                DbManager.DatabasePath = arguments["database"];
            }

            // Initialise database
            try
            {
                DbManager.CreateOrUpgradeDatabase();

                WebRequest.DefaultWebProxy = DbManager.Proxy;
                if (Settings.GetValue("AuthorGuid") == null)
                {
                    Settings.SetValue("AuthorGuid", Guid.NewGuid().ToString("B"));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not create or load the database file: " + ex.Message);
                return;
            }

            // Either run silently on command line...
            if (arguments["silent"] != null)
            {
                Kernel32.ManagedAttachConsole(Kernel32.ATTACH_PARENT_PROCESS);

                ApplicationJob[] jobs = DbManager.GetJobs();
                Updater updater = new Updater();
                updater.StatusChanged += new EventHandler<Updater.JobStatusChangedEventArgs>(updater_StatusChanged);
                updater.ProgressChanged += new EventHandler<Updater.JobProgressChangedEventArgs>(updater_ProgressChanged);
                updater.BeginUpdate(jobs, false, false);

                if (arguments["notify"] != null)
                {
                    m_Icon = new NotifyIcon();
                    m_Icon.Icon = System.Drawing.Icon.FromHandle(Properties.Resources.Restart.GetHicon());
                    m_Icon.Text = "Ketarin is working...";
                    m_Icon.Visible = true;
                }

                while (updater.IsBusy)
                {
                    Thread.Sleep(1000);
                }

                if (m_Icon != null)
                {
                    m_Icon.Dispose();
                }

                Kernel32.FreeConsole();
            }
            // ...perform database operations...
            else if (arguments["update"] != null && arguments["appguid"] != null)
            {
                // Update properties of an application in the database
                ApplicationJob job = DbManager.GetJob(new Guid(arguments["appguid"]));
                if (job == null) return;

                if (arguments["PreviousLocation"] != null)
                {
                    job.PreviousLocation = arguments["PreviousLocation"];
                }

                job.Save();
            }
            else if (arguments["export"] != null)
            {
                ApplicationJob[] jobs = DbManager.GetJobs();
                string exportedXml = ApplicationJob.GetXml(jobs, false, System.Text.Encoding.UTF8);
                try
                {
                    File.WriteAllText(arguments["export"] as string, exportedXml, System.Text.Encoding.UTF8); 
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Could export to the specified location: " + ex.Message);
                }
            }
            else if (arguments["install"] != null)
            {
                try
                {
                    // Install all applications in the given XML
                    ApplicationJob[] appsToInstall = null;
                    string path = arguments["install"] as string;
                    if (Uri.IsWellFormedUriString(path, UriKind.Absolute))
                    {
                        using (WebClient client = new WebClient())
                        {
                            appsToInstall = ApplicationJob.ImportFromXmlString(client.DownloadString(path), false);
                        }
                    }
                    else
                    {
                        appsToInstall = ApplicationJob.ImportFromXml(path);
                    }

                    InstallingApplicationsDialog dialog = new InstallingApplicationsDialog();
                    dialog.Applications = appsToInstall;
                    dialog.ShowIcon = true;
                    dialog.ShowInTaskbar = true;
                    dialog.AutoClose = (arguments["exit"] != null);
                    Application.Run(dialog);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Setup cannot be started: " + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            // ...or launch the GUI.
            else
            {
                Application.Run(new MainForm());
            }

            string logFile = arguments["log"];
            if (!string.IsNullOrEmpty(logFile))
            {
                try
                {
                    logFile = UrlVariable.GlobalVariables.ReplaceAllInString(logFile);
                    LogDialog.SaveLogToFile(logFile);
                }
                catch (Exception)
                {
                    // ignore errors
                }
            }
        }
Пример #2
0
 private void bInstall_Click(object sender, EventArgs e)
 {
     using (ChooseAppsToInstallDialog dialog = new ChooseAppsToInstallDialog())
     {
         if (dialog.ShowDialog(this) == DialogResult.OK)
         {
             using (InstallingApplicationsDialog setupDialog = new InstallingApplicationsDialog())
             {
                 setupDialog.UpdateApplications = dialog.ShouldUpdateApplications;
                 setupDialog.Applications = dialog.SelectedApplications;
                 setupDialog.ShowDialog(this);
             }
         }
     }
 }
Пример #3
0
 private void cmnuUpdateInstall_Click(object sender, EventArgs e)
 {
     using (InstallingApplicationsDialog setupDialog = new InstallingApplicationsDialog())
     {
         setupDialog.Applications = olvJobs.SelectedApplications;
         setupDialog.UpdateApplications = true;
         setupDialog.ShowDialog(this);
     }
 }
Пример #4
0
 private void InstallSelectedApplications()
 {
     using (InstallingApplicationsDialog setupDialog = new InstallingApplicationsDialog())
     {
         setupDialog.Applications = olvJobs.SelectedApplications;
         setupDialog.ShowDialog(this);
     }
 }