예제 #1
0
        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 { }
            }
        }
예제 #2
0
        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();
        }
예제 #3
0
        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();
        }