private void GetMsgIdString() { try { var updateOptions = new options.OptionsHandler("updator/uopts.txt"); if (updateOptions.contains("updatorGUID")) { msgId = updateOptions["updatorGUID", ""]; } } catch {} }
private static options.OptionsHandler getUpdatesInfo(string update, string name, string version, out string url) { var fpath = "lastversion.txtn"; var ipath = version == "" ? fpath : "lastversion-" + version + ".txtn"; var r = new response(); bool success = false; bool terminate = false; url = "http://" + (update + "/" + ipath).Replace("//", "/"); options.OptionsHandler updatesInfo; string last; do { try { last = r.getPage(url, ""); } catch (Exception e) { last = "\\error\\" + e.Message; } if (last.Length > 0 && last.StartsWith("\\error\\")) { if (last != "\\error\\nameresolution") { toUpdateLog(String.Format("error from web request {1}: {0}", last, url)); last = ""; if (last != "\\error\\Unable to connect to the remote server") { break; } } last = ""; } success = last.Length > 0; if (!success) { terminate = stopEvent.WaitOne(60 * 1000); } }while (!success && !terminate); if (last.Length <= 0) { return(null); } var fi = new FileInfo(fpath); if (fi.Exists && fi.Length > 32 * 1024) { toUpdateLog("delete logfile " + fpath); deleteFileWithTryes(fi.FullName); toUpdateLog("delete logfile " + fpath + " - deleted"); } File.AppendAllText(fpath, name + ":\r\n" + last + "\r\n\r\n"); updatesInfo = new options.OptionsHandler(); try { updatesInfo.readFromString(last); } catch (Exception e) { toUpdateLog(String.Format("error '{2}' from web request {1}: {0}", last, url, e.Message)); return(null); } toUpdateLog(String.Format("getted from web request {1}:\r\n\t{0}", last.Replace("\n", "\n\t"), url)); return(updatesInfo); }
private static string downloadUpdateNotSync(string dirName, string update, string name, string version, string[] args) { toUpdateLog("update\r\n\t" + update + "\r\n\t" + name + "\r\n\t" + stringArrayToLogString(args, "\t")); string url; string versionLV = ""; int CountOfTryes = 0; do { if (stopEvent.WaitOne(15000)) { return(""); } CountOfTryes++; options.OptionsHandler updatesInfo = getUpdatesInfo(update, name, versionLV, out url); if (updatesInfo == null) { var msg = "Программа '" + Application.ExecutablePath + "' не смогла найти нужную версию обновления для " + name; toUpdateLog(msg); if (CountOfTryes > 3) { MessageBox.Show(msg, "updatorvs8.ru"); return(""); } continue; } // полученная информация логируется в getUpdatesInfo непосредственно toUpdateLog("update from version " + version + ": info from url " + url /* + "\r\n\t" + updatesInfo.writeToString().Replace("\n", "\n\t")*/); if (!updatesInfo.contains("end")) { var msg = "Программа '" + Application.ExecutablePath + "' не обнаружила в файле информации об обновлениях поля end: " + name; toUpdateLog("Отсутствует поле end в файле описания обновления"); if (CountOfTryes > 3 || stopEvent.WaitOne(158000)) { MessageBox.Show(msg, "updatorvs8.ru"); return(""); } continue; } if (updatesInfo["name", ""] != name) { var msg = "Программа '" + Application.ExecutablePath + "' не смогла найти обновление. \r\n" + String.Format("Загрузка по url '{0}' дала несовместимый тип программы: ожидаемый тип {1}, фактический тип {2}", url, name, updatesInfo["name"]); toUpdateLog(msg); MessageBox.Show(msg); throw new Exception(String.Format("Загрузка по url '{0}' дала несовместимый тип программы: ожидаемый тип {1}, фактический тип {2}", url, name, updatesInfo["name"])); } if ( (updatesInfo["replace", true] && updatesInfo["version", ""] != version) || (version.CompareTo(updatesInfo["version", ""]) < 0) ) { toUpdateLog(String.Format( "to update replace/compare {0}/{1}", updatesInfo["replace", true], version.CompareTo(updatesInfo["version", ""]) )); var breakFlag = false; var eversions = updatesInfo["eralyes", ""].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); foreach (var ev in eversions) { if (ev.Length > 0 && version.CompareTo(ev) < 0 && ev.CompareTo(getVersionFromDate(DateTime.Now.AddDays(1.0))) <= 0 ) // защита от неверно установленной версии { versionLV = ev; breakFlag = true; toUpdateLog(String.Format("version {0} will be updated to {1}/{2} via {3} for {4}", version, updatesInfo["version", ""], updatesInfo["replace", true], versionLV, name)); // File.AppendAllText("via.st", argsString); // логирование.via.st break; } } if (!breakFlag) { return(downloadUpdateFile(dirName, update, name, updatesInfo["version", ""], args)); } } else { toUpdateLog(String.Format("version {0} must not be updated to version {1}/{2} for {3}", version, updatesInfo["version", ""], updatesInfo["replace", true], name)); return(""); } }while (true); }