Handles the updating process of a list of application jobs.
Exemple #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
                }
            }
        }
Exemple #2
0
        static void updater_StatusChanged(object sender, Updater.JobStatusChangedEventArgs e)
        {
            if (e.NewStatus == Updater.Status.Downloading)
            {
                // No status of interest
                return;
            }

            string status = e.ApplicationJob.Name + ": ";

            switch (e.NewStatus)
            {
                case Updater.Status.Failure:
                    status += "Failed.";
                    break;

                case Updater.Status.NoUpdate:
                    status += "No update available.";
                    break;

                case Updater.Status.UpdateSuccessful:
                    status += "Update successful.";
                    break;
            }

            Console.WriteLine(status);

            if (m_Icon != null)
            {
                m_Icon.ShowBalloonTip(2000, "Ketarin", status, (e.NewStatus == Updater.Status.Failure ? ToolTipIcon.Error : ToolTipIcon.Info));
            }
        }
Exemple #3
0
 static void updater_ProgressChanged(object sender, Updater.JobProgressChangedEventArgs e)
 {
     Console.WriteLine(e.ApplicationJob.Name + ": " + e.ProgressPercentage + "%");
 }
Exemple #4
0
 private void m_Updater_ProgressChanged(object sender, Updater.JobProgressChangedEventArgs e)
 {
     olvJobs.RefreshObject(e.ApplicationJob);
 }
Exemple #5
0
        private void m_Updater_StatusChanged(object sender, Updater.JobStatusChangedEventArgs e)
        {
            this.BeginInvoke((MethodInvoker)delegate() {
                olvJobs.RefreshObject(e.ApplicationJob);
                int index = olvJobs.IndexOf(e.ApplicationJob);
                if (index >= 0 && mnuAutoScroll.Checked)
                {
                    olvJobs.EnsureVisible(index);
                }

                UpdateNumByStatus();

                // Icon text length limited to 64 chars
                string text = "Currently working on: " + e.ApplicationJob.Name;
                if (text.Length >= 64)
                {
                    text = text.Substring(0, 60) + "...";
                }
                ntiTrayIcon.Text = text;
            });
        }
Exemple #6
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 += 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;
            }

            // Initialisation of protocols.
            WebRequest.RegisterPrefix("sf", new ScpWebRequestCreator());
            WebRequest.RegisterPrefix("httpx", new HttpxRequestCreator());

            // 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   += updater_StatusChanged;
                updater.ProgressChanged += updater_ProgressChanged;
                updater.BeginUpdate(jobs, false, false);

                if (arguments["notify"] != null)
                {
                    m_Icon = new NotifyIcon
                    {
                        Icon    = System.Drawing.Icon.FromHandle(Properties.Resources.Restart.GetHicon()),
                        Text    = "Ketarin is working...",
                        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"], exportedXml, System.Text.Encoding.UTF8);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Could not export to the specified location: " + ex.Message);
                }
            }
            else if (arguments["import"] != null)
            {
                string sourceFile = arguments["import"];
                try
                {
                    if (arguments["clear"] != null)
                    {
                        ApplicationJob.DeleteAll();
                    }

                    ApplicationJob.ImportFromXml(sourceFile);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Could not import from the specified location: " + ex.Message);
                }
            }
            else if (arguments["install"] != null)
            {
                try
                {
                    // Install all applications in the given XML
                    ApplicationJob[] appsToInstall;
                    string           path = arguments["install"];
                    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
                    {
                        Applications  = appsToInstall,
                        ShowIcon      = true,
                        ShowInTaskbar = true,
                        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
                }
            }
        }