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 { } } }
private void Main_Load(object sender, EventArgs e) { panelTab1.Visible = false; panelTab2.Visible = false; panelTab3.Visible = false; contextMenuStrip1.Renderer = new ArrowRenderer(); //Update Scripts new Thread(delegate() { this.BeginInvoke(new MethodInvoker(delegate() { Protocol.AddToProtocol("Started script update service", Types.Info); })); while (!IsDisposed) { try { if (Networking.NetworkReady()) { for (int i = 0; i < Networking.checkUpdate.Count; i++) { KeyValuePair <string, string> script = Networking.checkUpdate[i]; try { this.BeginInvoke(new MethodInvoker(delegate() { Protocol.AddToProtocol("Checking for update: " + script.Value, Types.Info); })); string version = ""; string[] lines = File.ReadAllLines(script.Value); foreach (string line in lines) { if (line.ToLower().Contains("version")) { version = GetLineItem(line); } } string result = Networking.CheckForUpdate(script.Key, version); if (result != "no" && result != "") { JObject updateInfo = JObject.Parse(result); this.BeginInvoke(new MethodInvoker(delegate() { Protocol.AddToProtocol("Updating: " + script.Value, Types.Info); })); if (Networking.DownloadScript(null, Int32.Parse(script.Key))) { string path = Path.GetDirectoryName(script.Value) + ""; JObject fileChanges = JObject.Parse(updateInfo["FileChanges"].ToString()); //Delete foreach (JToken delete in fileChanges["Delete"] as JArray) { try { File.Delete(path + delete); } catch { } } //Move foreach (JObject move in fileChanges["Move"]) { try { File.Move(path + move["From"], path + move["To"]); } catch { } } //Copy foreach (JObject copy in fileChanges["Copy"]) { try { File.Move(path + copy["From"], path + copy["To"]); } catch { } } try { Directory.Delete(Path.GetDirectoryName(Application.ExecutablePath) + @"\tmp\Update\", true); } catch { } Directory.CreateDirectory(Path.GetDirectoryName(Application.ExecutablePath) + @"\tmp\Update\"); if (!Directory.Exists(sf.streamlabsPath + @"Services\Scripts\" + script.Key + "\\")) { Directory.CreateDirectory(sf.streamlabsPath + @"Services\Scripts\" + script.Key + "\\"); } ZipFile.ExtractToDirectory(Path.GetDirectoryName(Application.ExecutablePath) + @"\tmp\Install.zip", Path.GetDirectoryName(Application.ExecutablePath) + @"\tmp\Update\"); //Copy files foreach (string dirPath in Directory.GetDirectories(Path.GetDirectoryName(Application.ExecutablePath) + @"\tmp\Update\", "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(dirPath.Replace(Path.GetDirectoryName(Application.ExecutablePath) + @"\tmp\Update\", sf.streamlabsPath + @"Services\Scripts\" + script.Key + "\\")); } foreach (string newPath in Directory.GetFiles(Path.GetDirectoryName(Application.ExecutablePath) + @"\tmp\Update\", "*.*", SearchOption.AllDirectories)) { try { File.Copy(newPath, newPath.Replace(Path.GetDirectoryName(Application.ExecutablePath) + @"\tmp\Update\", sf.streamlabsPath + @"Services\Scripts\" + script.Key + "\\"), true); } catch { } } //Delete temps File.Delete(Path.GetDirectoryName(Application.ExecutablePath) + @"\tmp\Install.zip"); Directory.Delete(Path.GetDirectoryName(Application.ExecutablePath) + @"\tmp\Update\", true); //Set ID foreach (FileInfo file in new DirectoryInfo(sf.streamlabsPath + @"Services\Scripts\" + script.Key + "\\").GetFiles()) { if (file.Name.Contains("_StreamlabsSystem.py") || file.Name.Contains("_AnkhBotSystem.py") || file.Name.Contains("_StreamlabsParameter.py") || file.Name.Contains("_AnkhBotParameter.py")) { bool found = false; lines = File.ReadAllLines(file.FullName); foreach (string line in lines) { if (line.Contains("ScriptBrowserID = ")) { found = true; break; } } if (!found) { using (StreamWriter writer = new StreamWriter(file.FullName)) { for (int ii = 0; ii < lines.Length; ii++) { writer.WriteLine(lines[ii]); if (lines[ii].ToLower().Contains("version") && !found) { writer.WriteLine("ScriptBrowserID = \"" + script.Key + "\""); found = true; } } if (!found) { writer.WriteLine(""); writer.WriteLine("ScriptBrowserID = \"" + script.Key + "\""); } } } break; } } IAsyncResult wait = BeginInvoke(new MethodInvoker(delegate() { Protocol.AddToProtocol("Successfully updated: " + script.Value, Types.Info); notifyIcon1.Tag = updateInfo["UpdateMessage"]; notifyIcon1.ShowBalloonTip(2000, "Updated Script", updateInfo["Name"].ToString(), ToolTipIcon.Info); notifyIcon1.BalloonTipText = updateInfo["Name"].ToString(); })); while (!wait.IsCompleted) { Thread.Sleep(500); } } } } catch (Exception ex) { this.BeginInvoke(new MethodInvoker(delegate() { Protocol.AddToProtocol("Could not update: " + script.Value + "\n" + ex.StackTrace, Types.Error); })); Console.WriteLine(ex.StackTrace); } IAsyncResult wait2 = BeginInvoke(new MethodInvoker(delegate() { Networking.checkUpdate.RemoveAt(i); })); while (!wait2.IsCompleted) { Thread.Sleep(1000); } i--; } } } catch (Exception ex) { this.BeginInvoke(new MethodInvoker(delegate() { Protocol.AddToProtocol("The update service has run into an error: " + ex.StackTrace, Types.Error); })); } Thread.Sleep(300000); } }).Start(); }