public static bool SendComment(Main form, int id, string comment, string reply) { if (CheckIp(form)) { using (MultipartFormDataContent data = new MultipartFormDataContent { { new StringContent(comment), "comment" }, { new StringContent(id + ""), "id" }, { new StringContent(reply), "reply" } }) using (HttpClient web = new HttpClient()) { string result = web.PostAsync(storageServer + "/Script%20Browser/addComment.php?user="******"&pass="******"Send Comment: Web-Result\n" + result, Types.Info); if (result.Contains("time")) { MetroMessageBox.Show(form, "Please wait a while befor posting a new comment.", "Don't Spam!", MessageBoxButtons.OK, MessageBoxIcon.Warning, 100); } else if (result.Contains("false")) { MetroMessageBox.Show(form, "Could't send your comment. Please try again later.", "Could not send comment", MessageBoxButtons.OK, MessageBoxIcon.Error, 100); } else { Protocol.AddToProtocol("Comment Send: " + comment, Types.Info); return(true); } } } return(false); }
public static void NotifySettings(Main form, int newcom, int newreply, int newbug) { tryagain: if (CheckIp(form)) { try { using (WebClient web = new WebClient()) { string result = web.DownloadString(storageServer + "/Script%20Browser/notifySettings.php?user="******"&pass="******"&newcom=" + newcom + "&newreply=" + newreply + "&newbug=" + newbug); Protocol.AddToProtocol("Updated notification settings: Web-Result\n" + result, Types.Info); if (result.Contains("false")) { MetroMessageBox.Show(form, "Could't update your notification settings. Please try again later.", "Could update settings", MessageBoxButtons.OK, MessageBoxIcon.Error, 100); } else if (result.Contains("true")) { Protocol.AddToProtocol("Updated notification settings", Types.Info); MetroMessageBox.Show(form, "Your notification settings have been updated!", "Settings updated", MessageBoxButtons.OK, MessageBoxIcon.Information, 100); } } } catch (Exception ex) { Protocol.AddToProtocol("Update Notification Settings: " + ex.Message + "!\n" + ex.StackTrace, Types.Error); if (DialogResult.Retry == SMB(form, "There was an unexpected network error!\nPlease make sure you have an internet connection.", "Network error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 2, DialogResult.Retry)) { goto tryagain; } } } }
public static PythonResult CheckPythonInstallation() { try { installedVersion = new Version(0, 0); RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Python.exe"); if (key == null) { key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Python.exe"); } if (key == null) { Protocol.AddToProtocol("Could not found Python!", Types.Warning); return(PythonResult.Nothing); } string pythonPath = key.GetValue(null).ToString(); key.Close(); ProcessStartInfo start = new ProcessStartInfo { FileName = pythonPath, Arguments = "--version", UseShellExecute = false, RedirectStandardError = true, CreateNoWindow = true }; using (Process process = Process.Start(start)) { using (StreamReader reader = process.StandardError) { try { string result = reader.ReadToEnd().Replace("Python ", "").Replace("\n", "").Replace("\r", ""); Version ver = new Version(result); Protocol.AddToProtocol("Python version " + ver + " detected. (" + pythonPath + ")", Types.Info); installedVersion = ver; if (ver.CompareTo(new Version(3, 0)) < 0 && ver.CompareTo(new Version(2, 0)) > 0) { return(PythonResult.Ok); } else { return(PythonResult.Wrong); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(PythonResult.Nothing); } } } } catch (Exception ex) { Protocol.AddToProtocol("Could not define Python version! " + ex.Message + "\n" + ex.StackTrace, Types.Error); } return(PythonResult.Error); }
public static string GetUploadUpdateInfo(Main form, string id) { try { if (CheckIp(form)) { using (WebClient web = new WebClient()) return(web.DownloadString(storageServer + "/Script%20Browser/getUUInfo.php?id=" + id)); } } catch (Exception ex) { Protocol.AddToProtocol("Get Upload Update Info: " + ex.Message + "\n" + ex.StackTrace, Types.Error); } return(""); }
public static bool IncreaseDownloads(Main form, int id) { try { if (CheckIp(form)) { using (WebClient web = new WebClient()) web.DownloadString(storageServer + "/Script%20Browser/increaseDownloads.php?id=" + id); return(true); } } catch (Exception ex) { Protocol.AddToProtocol("Increase Download: " + ex.Message + "\n" + ex.StackTrace, Types.Error); } return(false); }
public static bool DownloadScript(Main form, int id) { try { if (CheckIp(form)) { using (WebClient web = new WebClient()) web.DownloadFile(storageServer + "/Script%20Browser/Uploads/" + id, Path.GetDirectoryName(Application.ExecutablePath) + @"\tmp\Install.zip"); return(true); } } catch (Exception ex) { Protocol.AddToProtocol("Download Script: " + ex.Message + "\n" + ex.StackTrace, Types.Error); } return(false); }
public static bool UpdateIp() { try { using (WebClient web = new WebClient()) storageServer = web.DownloadString("http://www.digital-programming.com/StorageServer/getIP.php"); Protocol.AddToProtocol("Updated StorgeServers IP: " + storageServer, Types.Info); return(true); } catch (Exception ex) { Protocol.AddToProtocol("Update StorageServers IP: " + ex.Message + "\n" + ex.StackTrace, Types.Error); return(false); } }
public static void ChangeEMail(string email, string pass, Main form) { pass = Hash(pass); tryagain: try { CheckIp(form); using (WebClient web = new WebClient()) { string result = web.DownloadString(storageServer + "/Script%20Browser/changeEmail.php?user="******"&pass="******"&email=" + email); Protocol.AddToProtocol("Change E-Mail: Web-Result\n" + result, Types.Info); if (result.Contains("false")) { MetroMessageBox.Show(form, "Please check your password or try again later.", "Could not change E-Mail address", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 125); } else if (result.Contains("blacklist")) { MetroMessageBox.Show(form, "The email address \"" + email + "\" is blacklisted!\nContact us under \"[email protected]\" for more information.", "Could not change E-Mail address", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 150); } else if (result.Contains("email")) { MetroMessageBox.Show(form, "The email address \"" + email + "\" is allready registered!\nPlease select another one.", "Could not change E-Mail address", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 150); } else if (result.Contains("time")) { MetroMessageBox.Show(form, "You can only request a verification E-Mail once every 5 minuets.\nPlease wait...", "Could not change E-Mail address", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 150); } else { Protocol.AddToProtocol("Changed E-Mail", Types.Info); MetroMessageBox.Show(form, "Your new E-Mail address will be activated, after you verified it.\nPlease check your inbox for more information.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, 125); form.settings1.materialSingleLineTextField6.Text = ""; form.settings1.materialSingleLineTextField7.Text = ""; form.settings1.noFocusBorderBtn6.Visible = true; } } } catch (Exception ex) { Protocol.AddToProtocol("Change E-Mail: " + ex.Message + "!\n" + ex.StackTrace, Types.Error); if (DialogResult.Retry == SMB(form, "There was an unexpected network error!\nPlease make sure you have an internet connection.", "Network error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 2, DialogResult.Retry)) { goto tryagain; } } }
public static bool DeleteComment(Main form, string id) { if (CheckIp(form)) { using (WebClient web = new WebClient()) { string result = web.DownloadString(storageServer + "/Script%20Browser/deleteComment.php?id=" + id + "&user="******"&pass="******"Delete Comment: Web-Result\n" + result, Types.Info); if (result.Contains("true")) { return(true); } } } return(false); }
public SplashScreen(bool hide = false, string version = "") { if (version != "") { sf.version = version; sf.Save(); } Protocol.AddToProtocol("Starting protocol - SLCBSB Version: " + sf.version, Types.Info); this.DialogResult = DialogResult.No; this.hide = hide; InitializeComponent(); Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20)); webBrowser1.Url = new Uri("file://" + Path.GetDirectoryName(Application.ExecutablePath) + @"\HTML\SplashScreen.html"); }
public static void ChangeUsername(string _username, string pass, Main form) { pass = Hash(pass); tryagain: try { CheckIp(form); using (WebClient web = new WebClient()) { string result = web.DownloadString(storageServer + "/Script%20Browser/changeUsername.php?user="******"&newuser="******"&pass="******"Change Username: Web-Result\n" + result, Types.Info); if (result.Contains("false")) { MetroMessageBox.Show(form, "Please check your password or try again later.", "Could not change username", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 125); } else if (result.Contains("username")) { MetroMessageBox.Show(form, "Your new username has already been taken.", "Could not change username", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 125); } else { Protocol.AddToProtocol("Changed Username", Types.Info); MetroMessageBox.Show(form, "Your username has been successfully changed!", "Username changed", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, 125); form.settings1.materialSingleLineTextField4.Text = ""; form.settings1.materialSingleLineTextField5.Text = ""; Main.sf.username = _username; form.settings1.label1.Text = "Logged in as " + Main.sf.username; } } } catch (Exception ex) { Protocol.AddToProtocol("Change Username: "******"!\n" + ex.StackTrace, Types.Error); if (DialogResult.Retry == SMB(form, "There was an unexpected network error!\nPlease make sure you have an internet connection.", "Network error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 2, DialogResult.Retry)) { goto tryagain; } } }
public static void SendVerificationAgain(Main form) { tryagain: try { CheckIp(form); using (WebClient web = new WebClient()) { string result = web.DownloadString(storageServer + "/Script%20Browser/sendVerificationAgain.php?user="******"&pass="******"Send Verification E-Mail: Web-Result\n" + result, Types.Info); if (result.Contains("verfied")) { MetroMessageBox.Show(form, "Your account has already been verified!", "Could not send verification E-Mail again", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 125); form.settings1.noFocusBorderBtn6.Visible = false; } else if (result.Contains("time")) { MetroMessageBox.Show(form, "You can only request a verification E-Mail once every 5 minuets.\nPlease wait...", "Could not send verification E-Mail again", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 150); } else if (result.Contains("false")) { MetroMessageBox.Show(form, "Please try it later again.", "Could not send verification E-Mail again", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 125); } else { Protocol.AddToProtocol("New verification E-Mail send", Types.Info); MetroMessageBox.Show(form, "We send a new verification E-Mail to your address!\nPlease check your inbox.", "Send verification E - Mail again", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, 150); } } } catch (Exception ex) { Protocol.AddToProtocol("Send Verification E-Mail: " + ex.Message + "!\n" + ex.StackTrace, Types.Error); if (DialogResult.Retry == MetroMessageBox.Show(form, "There was an unexpected network error!\nPlease make sure you have an internet connection.", "Network error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 150)) { goto tryagain; } } }
public static void ChangePass(string oldPass, string newPass, Main form) { oldPass = Hash(oldPass); newPass = Hash(newPass); tryagain: try { CheckIp(form); using (WebClient web = new WebClient()) { string result = web.DownloadString(storageServer + "/Script%20Browser/changePassword.php?user="******"&pass="******"&newpass="******"Change Passwword: Web-Result\n" + result, Types.Info); if (result.Contains("false")) { MetroMessageBox.Show(form, "Please check your old password or try again later.", "Could not change password", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 125); } else { Protocol.AddToProtocol("Changed Password", Types.Info); MetroMessageBox.Show(form, "Your password has been successfully changed!", "Password changed", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, 125); form.settings1.materialSingleLineTextField1.Text = ""; form.settings1.materialSingleLineTextField2.Text = ""; form.settings1.materialSingleLineTextField3.Text = ""; Main.sf.password = newPass; } } } catch (Exception ex) { Protocol.AddToProtocol("Change Password: "******"!\n" + ex.StackTrace, Types.Error); if (DialogResult.Retry == SMB(form, "There was an unexpected network error!\nPlease make sure you have an internet connection.", "Network error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 2, DialogResult.Retry)) { goto tryagain; } } }
public static JObject Login(string _username, string _password, Main form, bool hashed = false, JObject info = null) { if (!hashed) { _password = Hash(_password); } tryagain: try { if (info == null) { CheckIp(form); } using (WebClient web = new WebClient()) { string result = ""; if (info == null) { result = web.DownloadString(storageServer + "/Script%20Browser/login.php?user="******"&pass="******"&getinfo=true"); Protocol.AddToProtocol("Login: Web-Result\n" + result, Types.Info); } if (!result.Contains("Twitch") && info == null) { MetroMessageBox.Show(form, "The username or password was incorrect.", "Login error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 100); Main.sf.username = ""; Main.sf.password = ""; Main.sf.Save(); } else { try { if (info == null) { info = JObject.Parse(result); } twitch = (bool)info["Twitch"]; form.settings1.label1.Text = "Logged in as " + info["Username"].ToString(); Protocol.AddToProtocol("Login: \"" + info["Username"].ToString() + "\"", Types.Info); form.settings1.checkBox1.Checked = (int)info["Notifys"]["NewCom"] == 1; form.settings1.checkBox2.Checked = (int)info["Notifys"]["NewReply"] == 1; form.settings1.checkBox3.Checked = (int)info["Notifys"]["NewBug"] == 1; form.settings1.noFocusBorderBtn8.Enabled = false; if (hashed) { form.settings1.tableLayoutPanel1.Visible = false; form.settings1.tableLayoutPanel2.Visible = true; form.settings1.tableLayoutPanel11.Visible = true; } else { form.settings1.animator1.HideSync(form.settings1.tableLayoutPanel1); form.settings1.animator1.Show(form.settings1.tableLayoutPanel2); form.settings1.animator1.Show(form.settings1.tableLayoutPanel11); } form.settings1.noFocusBorderBtn6.Visible = !(bool)info["Verified"]; foreach (JToken i in info["Scripts"] as JArray) { Main.sf.accountScripts.Add(i.ToString()); } Main.sf.username = info["Username"].ToString(); Main.sf.password = _password; Main.sf.Save(); form.localScripts1.ClearSelection(); } catch { return(JObject.Parse(result)); } } } } catch (Exception ex) { Protocol.AddToProtocol("Login: "******"!\n" + ex.StackTrace, Types.Error); Console.WriteLine(ex.StackTrace); if (DialogResult.Retry == SMB(form, "There was an unexpected network error!\nPlease make sure you have an internet connection.", "Network error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 2, DialogResult.Retry)) { goto tryagain; } } return(null); }
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 { } } }
public static void SignUp(string _username, string _password, string email, Main form, bool twitch = false, TwitchLogin webForm = null) { if (!twitch) { _password = Hash(_password); } tryagain: try { CheckIp(form); using (WebClient web = new WebClient()) { string result = ""; if (twitch) { result = web.DownloadString(storageServer + "/Script%20Browser/signUpTwitch.php?token=" + _password); webForm.Dispose(); } else { result = web.DownloadString(storageServer + "/Script%20Browser/signUp.php?username="******"&pass="******"&email=" + email); } Protocol.AddToProtocol("Signup: Web-Result (Twitch=" + twitch + ")\n" + result, Types.Info); if (result.Contains("username")) { MetroMessageBox.Show(form, "The username \"" + _username + "\" is allready registered!\nPlease select another one.", "Sign up error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 150); } else if (result.Contains("email")) { MetroMessageBox.Show(form, "The email address \"" + email + "\" is allready registered!\nPlease select another one.", "Sign up error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 150); } else if (result.Contains("blacklist")) { MetroMessageBox.Show(form, "The email address \"" + email + "\" is blacklisted!\nContact us under \"[email protected]\" for more information.", "Sign up error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 150); } else if (result.Contains("false")) { MetroMessageBox.Show(form, "There was an unexected sign up error.\nPlease try again later.", "Sign up error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 150); } else if (result.Contains("verify")) { MetroMessageBox.Show(form, "Your Twitch account wasn't verified yet!\nPlease verify your email address.", "Sign up error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 150); } else { if (!twitch) { MetroMessageBox.Show(form, "You signed up successfully!\nA verification email has been send to your email account. Please check your inbox.", "Sign up success", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, 150); } Protocol.AddToProtocol("Signup: \"" + _username + "\"", Types.Info); Main.sf.username = _username; if (twitch) { Main.sf.password = Hash(_password); } else { Main.sf.password = _password; } Networking.twitch = twitch; form.settings1.label1.Text = "Logged in as " + Main.sf.username; form.settings1.tableLayoutPanel7.Visible = !twitch; form.settings1.tableLayoutPanel9.Visible = !twitch; form.settings1.tableLayoutPanel10.Visible = !twitch; form.settings1.noFocusBorderBtn6.Visible = !twitch; form.settings1.animator1.Hide(form.settings1.tableLayoutPanel1); form.settings1.animator1.Show(form.settings1.tableLayoutPanel2); form.settings1.animator1.Show(form.settings1.tableLayoutPanel11); form.settings1.noFocusBorderBtn8.Enabled = false; form.settings1.checkBox1.Checked = true; form.settings1.checkBox2.Checked = true; form.settings1.checkBox3.Checked = true; Main.sf.Save(); form.localScripts1.ClearSelection(); } } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); try { webForm.Dispose(); } catch { } Protocol.AddToProtocol("Signup: " + ex.Message + "!\n" + ex.StackTrace, Types.Error); if (DialogResult.Retry == SMB(form, "There was an unexpected network error!\nPlease make sure you have an internet connection.", "Network error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 2, DialogResult.Retry)) { goto tryagain; } } }
private void Upload(object sender, EventArgs e) { try { noFocusBorderBtn8.Visible = false; label10.Text = "Uploading your script... This could take some seconds!"; label10.Refresh(); string path = Path.GetDirectoryName(Application.ExecutablePath) + @"\tmp\Script\"; PrepareFile(); string[] add = new string[] { materialSingleLineTextField1.Text, materialSingleLineTextField4.Text }; AddToListNotExists(add); JObject info = new JObject(); info["Name"] = materialSingleLineTextField1.Text; info["ShortDescription"] = materialSingleLineTextField2.Text; info["Version"] = materialSingleLineTextField3.Text; info["Alias"] = materialSingleLineTextField4.Text; if (metroComboBox1.SelectedIndex == 0) { info["Type"] = "Command"; } else { info["Type"] = "Parameter"; } info["LongDescription"] = richTextBox1.Text; info["Tags"] = new JArray(searchTags.ToArray()); string result = Networking.UploadScript(this, info.ToString(), Path.GetDirectoryName(Path.GetDirectoryName(path)) + "\\script.zip"); Protocol.AddToProtocol("Upload Script: Web-Result\n" + result, Types.Info); if (result.Contains("verify")) { MetroMessageBox.Show(this, "Your email address has not been verified yet.\nPlease check your inbox or contact us over [email protected]", "Upload Error", MessageBoxButtons.OK, MessageBoxIcon.Error, 150); } else if (result.Contains("enough")) { MetroMessageBox.Show(this, "You have reached the maximum amount of scripts for a single user!\nDelete some to upload new ones.", "Upload Error", MessageBoxButtons.OK, MessageBoxIcon.Error, 150); } else if (result.Contains("true")) { label10.Text = "Your script has been successfully uploaded and will be published after our inspection!"; uploaded = true; Main.sf.accountScripts.Add(result.Replace("true", "")); noFocusBorderBtn6.Text = "Finish"; noFocusBorderBtn8.Enabled = false; File.Delete(Path.GetDirectoryName(Path.GetDirectoryName(path)) + "\\script.zip"); //Update local script file string[] lines = File.ReadAllLines(this.path); using (StreamWriter writer = new StreamWriter(this.path)) { bool found = false; for (int i = 0; i < lines.Length; i++) { writer.WriteLine(lines[i]); if (lines[i].ToLower().Contains("version") && !found) { writer.WriteLine("ScriptBrowserID = \"" + result.Replace("true", "") + "\""); found = true; } } if (!found) { writer.WriteLine(""); writer.WriteLine("ScriptBrowserID = \"" + result.Replace("true", "") + "\""); } } return; } File.Delete(Path.GetDirectoryName(Path.GetDirectoryName(path)) + "\\script.zip"); } catch (Exception ex) { Protocol.AddToProtocol("Upload Script: " + ex.Message + "\n" + ex.StackTrace, Types.Error); Console.WriteLine(ex.StackTrace); } label10.Text = "There was an error while uploading your script :/"; noFocusBorderBtn8.Visible = true; }
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(); }