Beispiel #1
0
        private void Btn_FileDownloadedAndRunned(object sender, EventArgs e)
        {
            CheckingRoutine();

            // FIXME: Should I do this in DownloadButton maybe?
            if (SessionStorage.inside.RemoveUpdateFileAfterInstall)
            {
                DownloadButton btn = (sender as DownloadButton);
                File.Delete(btn.UpdateFilename);
            }
        }
Beispiel #2
0
        private void CheckingRoutine()
        {
            // Cleaning up a bit
            //flowDownloads.Controls.Clear();

            labelVersion.Text = Loc.Get("frmMain.labelVersion.Text.CheckingRoutine.Checking", "Checking...");
            Log.Write("Checking for updates on the medoc.ua server");

            bool success = medoc.RefreshDoc();

            if (success)
            {
                MedocVersion version = medoc.GetLatestVersion();
                if (!MedocVersion.IsValid(version))
                {
                    Log.Write("Application cannot get the latest remote M.E.Doc version");
                    return;
                }

                //version = "11.01.023";
                labelVersion.Text = String.Format(Loc.Get("frmMain.labelVersion.Text.CheckingRoutine.LatestVersion", "Latest version: {0}"), version);

                //MedocVersion test = new MedocVersion(version);

                //MedocVersion test2 = "11.01.024";
                //MedocVersion test3 = "11.01.023";


                MedocVersion localversion = localmedoc.LocalVersion;
                if (!MedocVersion.IsValid(version))
                {
                    Log.Write("Application cannot get a local version of M.E.Doc installation.");
                    MessageBox.Show(
                        Loc.Get("frmMain.MessageBox.CheckingRoutine.NoLocalVersion", "This application must be ran only on systems with M.E.Doc installed."),
                        "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    return;
                }
                //localversion = "11.01.021";
                labelLocalVersion.Text = String.Format(Loc.Get("frmMain.labelLocalVersion.Text.CheckingRoutine.LatestLocalVersion", "Latest local version: {0}"), localversion);

                Log.Write(labelVersion.Text);
                Log.Write(labelLocalVersion.Text);

                // Does some updates are performing now? Then don't recreate the buttons
                // FIXME: Still can be a better solution probably
                bool isStillUpdating = false;
                foreach (DownloadButton button in flowDownloads.Controls)
                {
                    if (button.IsUpdating)
                    {
                        isStillUpdating = true;
                        break;
                    }
                }

                if (!isStillUpdating)
                {
                    MedocDownloadItem[] items;
                    success = medoc.GetItems(out items);
                    if (success)
                    {
                        /*
                         *      if (lastDownloadsCount != items.Length)
                         *      {
                         *              // Initial download items update
                         *              //if(lastDownloadsCount == 0)
                         *              if(false) // Test
                         *              {
                         *                      flowDownloads.Controls.Clear();
                         *                      foreach (MedocDownloadItem item in items)
                         *                      {
                         *                              DownloadButton btn = new DownloadButton(item);
                         *                              btn.IsHighlighted = (item.version > localversion);
                         *                              btn.FileDownloadedAndRunned += Btn_FileDownloadedAndRunned;
                         *                              flowDownloads.Controls.Add(btn);
                         *
                         *                              //	Console.WriteLine("Added {0}", item.link);
                         *                      }
                         *              }
                         *              else // Update count was changed since the last checking for updates
                         *              {
                         *                      // Determine what count should we add to existing download items
                         *                      int newItemsCount = items.Length - lastDownloadsCount;
                         *                      int i = 0;
                         *                      for (; newItemsCount > 0; newItemsCount--, i++)
                         *                      {
                         *                              //MedocDownloadItem item = items[newItemsCount-1]; // Reverse order
                         *                              MedocDownloadItem item = items[i];
                         *                              DownloadButton btn = new DownloadButton(item);
                         *                              btn.IsHighlighted = (item.version > localversion);
                         *                              btn.FileDownloadedAndRunned += Btn_FileDownloadedAndRunned;
                         *                              flowDownloads.Controls.Add(btn); // This whole thing might be working if I could add to the begin of the Controls
                         *                      }
                         *              }
                         *
                         *              lastDownloadsCount = items.Length;
                         *      }
                         */

                        flowDownloads.Controls.Clear();
                        foreach (MedocDownloadItem item in items)
                        {
                            DownloadButton btn = new DownloadButton(item);
                            btn.IsHighlighted            = (item.version > localversion);
                            btn.FileDownloadedAndRunned += Btn_FileDownloadedAndRunned;
                            flowDownloads.Controls.Add(btn);

                            //	Console.WriteLine("Added {0}", item.link);
                        }
                    }
                }

                Status(Loc.Get("frmMain_Done", "Done."));
                trayIcon.Text = labelVersion.Text + "\r\n" + labelLocalVersion.Text;

                if (localversion != version)
                {
                    trayIcon.ShowBalloonTip(5000, Loc.Get("frmMain.trayIcon.BalloonTipTitle.CheckingRoutine.UpdateReleased", "M.E.Doc update has been released!"),
                                            labelVersion.Text + "\r\n" + labelLocalVersion.Text, ToolTipIcon.Info);
                }
                else
                {
                    if (this.WindowState != FormWindowState.Minimized)
                    {
                        trayIcon.ShowBalloonTip(5000, Loc.Get("frmMain.trayIcon.BalloonTipTitle.CheckingRoutine.NoUpdates", "No updates for M.E.Doc"),
                                                String.Format(Loc.Get("frmMain.trayIcon.BalloonTipText.CheckingRoutine.NoUpdates", "Minimize the app to deny \"no updates\" notifications\r\n{0}"),
                                                              labelVersion.Text + "\r\n" +
                                                              labelLocalVersion.Text), ToolTipIcon.Info);
                    }
                }

                if (ParsedArgs.GetToken("telegramforcemsg") || localversion != version)
                {
                    string versionChangelog = medoc.GetLatestChangelog();

                    telegram.SendMessageAll(String.Format(Loc.Get("frmMain.telegram.CheckingRoutine.UpdateAvailable", "Update from {0} to [{1}]({2}) is available"),
                                                          localversion, version, versionChangelog),
                                            Telegram.Bot.Types.Enums.ParseMode.Markdown);
                }
            }
            else
            {
                labelVersion.Text = Loc.Get("frmMain.labelVersion.Text.CheckingRoutine.Error", "Something went wrong");
                Log.Write("Cannot connect to medoc.ua");
                Status(Loc.Get("frmMain.Status.CheckingRoutine.CannotConnect", "Cannot connect to medoc.ua"));
            }
        }