public void InitApp(object sender, StartupEventArgs e) { File.WriteAllText(@"./Updater_log.txt", ""); //Show something so users don't get confused _initDialog.DoWork += InitDialog_DoWork; _initDialog.RunWorkerAsync(); var assembly = Assembly.GetExecutingAssembly(); var fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); _strUpdaterVersion = fileVersionInfo.ProductVersion; Utils.LOG($"Info| Updater version: {_strUpdaterVersion}"); Utils.LOG("Info| Creating Web Handler"); _webClient = new WebClient(); Utils.LOG("Info| Done."); Utils.LOG("Info| Creating INI handler"); //Proceed _iniDataParser = new FileIniDataParser(); _iniDataParser.Parser.Configuration.CommentString = "#"; //Dirty code incoming! try { _iniSettingsData = _iniDataParser.ReadFile("./updater.ini", Encoding.ASCII); } catch (Exception ex) { Utils.ProcessBadConfig(ex); } Thread.Sleep(100); //Wait a bit try { _bSkipUpdates = bool.Parse(_iniSettingsData["Dev"]["SkipUpdates"]); } catch (Exception ex) { Utils.ProcessBadConfig(ex); } Utils.LOG("Info| Done."); Utils.LOG($"Info| Skip_updates: {_bSkipUpdates}"); //Get app version MessageBoxResult result; //Download list Utils.LOG($"Info| Downloading main list from server: {StrServerUrl}fileList"); try { _jsonInfoFile = _webClient.DownloadString($"{StrServerUrl}fileList"); var jsonVersionInfo = _webClient.DownloadString($"{StrServerUrl}version"); var versionInfo = JsonConvert.DeserializeObject <Dictionary <string, string> >(jsonVersionInfo); if (!versionInfo.TryGetValue("Updater", out _strUpdaterOnlineVersion) || !versionInfo.TryGetValue("UpdaterDL", out _downloadLink) || !versionInfo.TryGetValue("RoRVersion", out StrOnlineVersion)) { throw new ApplicationException("Failed to get Versioninfo."); } Utils.LOG($"Info| Updater: {_strUpdaterOnlineVersion}"); Utils.LOG($"Info| Rigs-of-Rods: {StrOnlineVersion}"); Utils.LOG("Info| Done."); } catch (Exception ex) { result = MessageBox.Show("Could not connect to the main server.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); if (result == MessageBoxResult.OK) { Utils.LOG("Error| Failed to connect to server."); Utils.LOG(ex.ToString()); Quit(); } } if (_strUpdaterVersion != _strUpdaterOnlineVersion && !_bSkipUpdates) { ProcessSelfUpdate(); } Thread.Sleep(10); //Wait a bit Utils.LOG("Info| Reading file..."); try { FilesInfo = JsonConvert.DeserializeObject <List <RoRUpdaterItem> >(_jsonInfoFile); } catch (Exception ex) { result = MessageBox.Show("Could not read file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); if (result == MessageBoxResult.OK) { Utils.LOG("Error| Failed to read file."); Utils.LOG(ex.ToString()); Quit(); } } try { //Use Product version instead of file version because we can use it to separate Dev version from release versions, same for TestBuilds var versionInfo = FileVersionInfo.GetVersionInfo("RoR.exe"); StrLocalVersion = versionInfo.ProductVersion; Utils.LOG("Info| local RoR ver: " + StrLocalVersion); } catch { StrLocalVersion = "unknown"; Utils.LOG("Info| Game Not found!"); } Utils.LOG("Info| Done."); Utils.LOG("Succes| Initialization done!"); _bInit = true; _initDialog = null; //We don't need it anymore.. :3 _pageSwitcher = new PageSwitcher(); _pageSwitcher.Show(); _pageSwitcher.Activate(); }
public void InitApp(object sender, StartupEventArgs e) { //Clean up first File.Delete("Updater_log.txt"); File.Delete("updater.exe"); //We don't need this anymore File.Delete("ror-updater_selfupdate.exe"); LOG("Info| RoR_Updater ver:" + str_updater_version); _dispatcher = Dispatcher.CurrentDispatcher; //Show something so users don't get confused InitDialog.DoWork += InitDialog_DoWork; InitDialog.RunWorkerAsync(); LOG("Info| Creating Web Handler"); webClient = new WebClient(); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); LOG("Info| Done."); LOG("Info| Creating INI handler"); //Proceed fileIniData = new FileIniDataParser(); fileIniData.Parser.Configuration.CommentString = "#"; //Dirty code incoming! try { data = fileIniData.ReadFile("./updater.ini", System.Text.Encoding.ASCII); } catch (Exception ex) { ProcessBadConfig(ex); } Thread.Sleep(100); //Wait a bit try { b_DevBuilds = bool.Parse(data["Main"]["DevBuilds"]); b_skipUpdates = bool.Parse(data["Dev"]["SkipUpdates"]); str_local_devbuild = data["Dev"]["DevBuildVer"].ToString(); } catch (Exception ex) { ProcessBadConfig(ex); } LOG("Info| Done."); LOG("Info| DevBuilds: " + b_DevBuilds.ToString() + " Skip_updates: " + b_skipUpdates.ToString() + " DevBuildNum: " + str_local_devbuild); //Get app version MessageBoxResult result; try { //Use Product version instead of file version because we can use it to separate Dev version from release versions, same for TestBuilds var versionInfo = FileVersionInfo.GetVersionInfo("RoR.exe"); str_local_version = versionInfo.ProductVersion; LOG("Info| local RoR ver: " + str_local_version); } catch (Exception ex) { str_local_version = "unknown"; //Todo: Make it install the game too. LOG("Error| Game Not found!"); result = MessageBox.Show("Game not found! \nMove me to game's root folder!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); //Make the app wait and not continue if (result == MessageBoxResult.OK) Quit(); } //Download list LOG("Info| Downloading main list from server: " + str_server_url); try { webClient.DownloadFile(str_server_url + "List.xml", @"./List.xml"); LOG("Info| Done."); } catch (Exception ex) { result = MessageBox.Show("Could not connect to the main server.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); if (result == MessageBoxResult.OK) { LOG("Error| Failed to connect to server."); LOG(ex.ToString()); Quit(); } } Thread.Sleep(10); //Wait a bit LOG("Info| Creating XML handler, reading file..."); xml_ListFile = new XmlDocument(); xml_ListFile.Load("List.xml"); LOG("Info| Done."); elemList = xml_ListFile.GetElementsByTagName("server"); for (int i = 0; i < elemList.Count; i++) { str_online_version = elemList[i].Attributes["ror"].Value; str_updater_online_version = elemList[i].Attributes["version"].Value; //Temporary //Forced dev mode if (str_online_version.EndsWith("-dev")) b_DevBuilds = true; if (b_DevBuilds) str_online_devbuild = elemList[i].Attributes["dev"].Value; } LOG("Succes| Initialization done!"); #if (!DEBUG) if (str_updater_version != str_updater_online_version && !b_skipUpdates) processSelfUpdate(); #endif b_Init = true; InitDialog = null; //We don't need it anymore.. :3 pageSwitcher = new PageSwitcher(this); pageSwitcher.Show(); pageSwitcher.Activate(); }