internal MedocVersion GetLatestVersion() { HtmlNodeCollection downloadsItems = DownloadsItems(); if (downloadsItems == null) { Log.Write(LogLevel.EXPERT, "MedocAPI: Cannot get items from the download-items"); return(""); } MedocVersion version = GetVersion(downloadsItems[0]); Console.WriteLine("{0}", version); return(version); }
// Replaced with a new detection method! (evidences line 2) internal bool GetDSTVersion(out MedocVersion version) { version = new MedocVersion(); string[] allLogFiles = new string[0]; if (!GetLatestLogs(out allLogFiles)) { return(false); } string value = ""; for (int i = allLogFiles.Length - 1; i >= 0; i--) { string logFile = allLogFiles[i]; if (logFile.Trim().Length <= 0) { Log.Write(LogLevel.EXPERT, "MedocInternal: Unexpected log list searching error"); continue; } value = ReadLogFile(logFile); // Check if the latest log contains DSTVERSION at all // If not - then check all the previous if (value.Trim().Length > 0) { break; } Log.Write(LogLevel.NORMAL, "MedocInternal: Cannot find DSTVERSION key in " + logFile); } // Always take the latest value Regex regex = new Regex(@"\d{2}.\d{2}.\d{3}"); if (!regex.IsMatch(value)) { Log.Write("MedocInternal: Update version doesn't match the expected pattern (xx.xx.xxx)"); return(false); } version = (MedocVersion)value; // Added explicit conversion for convenience return(true); }
// http://www.blackbeltcoder.com/Articles/strings/a-sscanf-replacement-for-net internal bool GetLastUpdateVersion(out MedocVersion version) { version = new MedocVersion(); ScanFormatted parser = new ScanFormatted(); string[] allLogFiles = new string[0]; if (!GetLatestLogs(out allLogFiles)) { return(false); } for (int i = allLogFiles.Length - 1; i >= 0; i--) { string logFile = allLogFiles[i]; if (logFile.Trim().Length <= 0) { Log.Write(LogLevel.EXPERT, "MedocInternal: Unexpected log list searching error"); continue; } // string[] file = new string[] { }; try { file = File.ReadAllLines(logFile); } catch (Exception ex) { Log.Write(LogLevel.NORMAL, "Cannot read a latest log file\r\n" + ex.Message); } // Search from the end to start of the file for (int j = file.Length - 1; j >= 0; j--) { string line = file[j]; // bool foundNewVerString = GetLine(line, "newVer"); if (!foundNewVerString) { continue; } int newVerIdx = line.IndexOf("newVer"); if (newVerIdx + "newVer".Length >= line.Length) { continue; } line = line.Substring(newVerIdx); // ScanFormatted fricks stuff up after parsing %s for some reason (doesn't care it's Ukrainian word of English (i.e. "is1C = False")) //string lineformat = "%d.%d.%d %d:%d:%d.%d %s INFO %s: is1C = %s, newVer = %d, newRel = %d, newBld = %d"; string lineformat = "newVer = %d, newRel = %d, newBld = %d"; int count = parser.Parse(line, lineformat); //if(count > 9 /*&& count <= 13*/) if (count == 3) { version = new MedocVersion((int)parser.Results[0], (int)parser.Results[1], (int)parser.Results[2]); Console.WriteLine("Found version: {0}", version.Version); return(true); } } } return(false); }
public static bool GetLocalDistributionVersion(out MedocVersion version) { version = new MedocVersion(); // Getting a subkey string[] regPaths = new string[1] { "Software\\M.E.Doc\\M.E.Doc", }; RegistryKey key; foreach (string regPath in regPaths) { key = Registry.LocalMachine.OpenSubKey(regPath); if (key == null) { Log.Write(LogLevel.NORMAL, "MedocInternal: Cannot find local distribution path at HKLM"); continue; } string[] versions = key.GetSubKeyNames(); // Find the latest subkey from all MedocVersion latestVersion = new MedocVersion(); foreach (string versionStr in versions) { MedocVersion testVersion = new MedocVersion(); if (!MedocVersion.GetVersion(versionStr, out testVersion)) { continue; } if (testVersion > latestVersion) { latestVersion = testVersion; } } version = latestVersion; return(true); } foreach (string regPath in regPaths) { key = Registry.CurrentUser.OpenSubKey(regPath); if (key == null) { Log.Write(LogLevel.NORMAL, "MedocInternal: Cannot find local distribution path at HKCU"); continue; } string[] versions = key.GetSubKeyNames(); // Find the latest subkey from all MedocVersion latestVersion = new MedocVersion(); foreach (string versionStr in versions) { MedocVersion testVersion = new MedocVersion(); if (!MedocVersion.GetVersion(versionStr, out testVersion)) { continue; } if (testVersion > latestVersion) { latestVersion = testVersion; } } version = latestVersion; return(true); } Log.Write(LogLevel.NORMAL, "MedocInternal: Cannot get local distribution path from registry"); return(false); }
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")); } }