private void Start() { label1.Text = "Checking for Updates"; downloadThread = new Thread(delegate() { try { Console.WriteLine("Current version: " + sf.version); if (!CheckUpdate()) { this.BeginInvoke(new MethodInvoker(delegate() { label1.Text = "Updating - Downloading Files..."; })); List <string> failedChanges = new List <string>(); List <string> failedRemoves = new List <string>(); JArray changelog = GetChangelog(); while (changelog.First["version"].ToString() != sf.version) { changelog.RemoveAt(0); } changelog.RemoveAt(0); JObject changes = GetChanges(changelog); //Add folders foreach (JToken addFolder in changes["folders"]["added"]) { if (!Directory.Exists(directory + addFolder.ToString())) { Directory.CreateDirectory(directory + addFolder.ToString()); } } //Remove Folders foreach (JToken removeFolder in changes["folders"]["removed"]) { try { Directory.Delete(directory + removeFolder.ToString(), true); } catch { failedRemoves.Add(directory + removeFolder.ToString()); } } //Download files SetProgress(0); using (WebClient web = new WebClient()) { web.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadFileProgressChanged); web.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted); int counter = 1; foreach (JToken addedFile in changes["files"]["changed"]) { try { this.BeginInvoke(new MethodInvoker(delegate() { label1.Text = "Updating - Downloading Files (" + counter + "/" + ((JArray)changes["files"]["changed"]).Count + ")"; })); downloadingFile = true; bool fileDeleted = false; try { File.Delete(directory + addedFile); fileDeleted = true; web.DownloadFileAsync(new Uri("http://digital-programming.de/ScriptBrowser/bin" + addedFile), directory + addedFile); } catch { web.DownloadFileAsync(new Uri("http://digital-programming.de/ScriptBrowser/bin" + addedFile), directory + "\\Updater\\" + failedChanges.Count); } while (downloadingFile) { Thread.Sleep(50); } if (!fileDeleted && !failedChanges.Contains(addedFile.ToString()) && downloadError == null) { failedChanges.Add(addedFile.ToString()); } if (downloadError != null) { Console.WriteLine(downloadError); if (downloadError.InnerException.GetType().ToString() == "System.IO.IOException") { try { if (!failedChanges.Contains(addedFile.ToString())) { web.DownloadFile("http://digital-programming.de/ScriptBrowser/bin" + addedFile, directory + "\\Updater\\" + failedChanges.Count); failedChanges.Add(addedFile.ToString()); } } catch { this.BeginInvoke(new MethodInvoker(delegate() { label1.Text = "Retry - 10s"; })); downloadThread.Abort(); return; } } else { this.BeginInvoke(new MethodInvoker(delegate() { label1.Text = "Retry - 10s"; })); downloadThread.Abort(); return; } downloadError = null; } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } counter++; } } SetProgress(0); //Delete files this.BeginInvoke(new MethodInvoker(delegate() { label1.Text = "Cleaning Up..."; })); foreach (JToken removeFile in changes["files"]["removed"]) { try { File.Delete(directory + removeFile); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); failedRemoves.Add(removeFile.ToString()); } } sf.version = changelog.Last["version"].ToString(); sf.Save(); if (failedChanges.Count != 0) { File.WriteAllLines(directory + "\\Updater\\changeFiles.txt", failedChanges); } if (failedRemoves.Count != 0) { File.WriteAllLines(directory + "\\Updater\\remove.txt", failedRemoves); } if (failedChanges.Count != 0 || failedRemoves.Count != 0) { Process.Start(directory + "\\Updater\\Updater.exe"); this.BeginInvoke(new MethodInvoker(delegate() { this.DialogResult = DialogResult.OK; this.Dispose(); })); return; } } try { using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Script Browser", true)) key.SetValue("DisplayVersion", sf.version); } catch { } //Receiving Data this.BeginInvoke(new MethodInvoker(delegate() { label1.Text = "Receiving Data"; })); JArray topScriptsData = JArray.Parse(Networking.GetTopScripts("Command", "Rating", 1, null)); //Login JObject login = null; if (sf.username != "") { this.BeginInvoke(new MethodInvoker(delegate() { label1.Text = "Login"; })); try { login = Networking.Login(sf.username, sf.password, null, true); } catch { } } //Close & Start this.BeginInvoke(new MethodInvoker(delegate() { label1.Text = "Starting Script-Browser"; label1.Update(); main = new Main(topScriptsData, hide, login); this.DialogResult = DialogResult.OK; minimized.Enabled = true; })); return; } catch (Exception ex) { this.BeginInvoke(new MethodInvoker(delegate() { label1.Text = "Retry - 10s"; })); Console.WriteLine(ex.StackTrace); } SetProgress(0); }); downloadThread.Start(); }
public Main(JArray topScriptsData, bool hide = false, JObject login = null) { this.hide = hide; //Check SLCB if (!Set_SCB_Path.CheckSLCBPath(sf.streamlabsPath)) { Protocol.AddToProtocol("Could not find valid Streamlabs Chatbot path!", Types.Warning); if (!Set_SCB_Path.CheckSLCBPath(Set_SCB_Path.GetSLCBPath())) { new Set_SCB_Path(sf.streamlabsPath).ShowDialog(); } else { sf.streamlabsPath = Set_SCB_Path.GetSLCBPath(); } } if (!Set_SCB_Path.CheckSLCBPath(sf.streamlabsPath)) { Environment.Exit(0); } //Check Python Console.WriteLine(sf.checkPythonVersion); try { CheckPython.PythonResult python = CheckPython.CheckPythonInstallation(); if ((python == CheckPython.PythonResult.Nothing || python == CheckPython.PythonResult.Wrong) && sf.checkPythonVersion) { new CheckPython().ShowDialog(); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } sf.Save(); InitializeComponent(); Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20)); selectedTabPage = tableLayoutPanel3; navbarTransitionIn.Add(tableLayoutPanel3); lastWinSize = Size; lastWinPos = Location; label9.Text = "Version " + sf.version; topScripts1.form = this; search1.form = this; settings1.form = this; localScripts1.form = this; topScripts1.LoadList(topScriptsData); if (login != null) { Networking.Login(sf.username, sf.password, this, true, login); } if (Directory.Exists(Path.GetDirectoryName(Application.ExecutablePath) + @"\blob_storage")) { try { Directory.Delete(Path.GetDirectoryName(Application.ExecutablePath) + @"\blob_storage", true); } catch { } } if (Directory.Exists(Environment.CurrentDirectory + @"\blob_storage")) { try { Directory.Delete(Environment.CurrentDirectory + @"\blob_storage", true); } catch { } } }