示例#1
0
        // Saves Key to App File
        public bool SaveKey(string key)
        {
            // The folder for the roaming current user
            string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            // Combine the base folder with your specific folder....
            string specificFolder = folder + "/scarlet";

            // Check if folder exists and if not, create it
            if (!Directory.Exists(specificFolder))
            {
                Directory.CreateDirectory(specificFolder);
            }


            if (string.Equals(ScarletAPI.Request("user", "info", key, "id"), ""))
            {
                return(false);
            }
            else
            {
                // Compose a string that consists of three lines.
                string lines = key;

                // Write the string to a file.
                System.IO.StreamWriter file = new System.IO.StreamWriter(specificFolder + "/scarlet_config.cfg");
                file.WriteLine(lines);

                file.Close();
                return(true);
            }
        }
示例#2
0
 // Check Current version on Server
 public static void testConnection(Scarlet ScarletForm)
 {
     try { ScarletAPI.Request(""); }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(ex.Message.ToString(), "No connection to Scarlet Servers.");
         Environment.Exit(1);
     }
 }
示例#3
0
        public void ChooseFolder()
        {
            var installDirFromAPI = JsonObject.readFrom(ScarletAPI.Request("user", "info", Username)).get("installDir");

            if (!installDirFromAPI.isString())
            {
                installDirectory = "";
            }
            else
            {
                installDirectory = installDirFromAPI.asString();
            }

            this.Invoke((Action) delegate {
                using (var owner = new Form()
                {
                    Width = 0,
                    Height = 0,
                    StartPosition = FormStartPosition.CenterScreen,
                    Text = "Browse for Folder"
                })
                {
                    var folderBrowser                 = new FolderBrowserDialog();
                    folderBrowser.Description         = "Select Scarlet Installation Folder";
                    folderBrowser.RootFolder          = Environment.SpecialFolder.Desktop;
                    folderBrowser.SelectedPath        = installDirectory;
                    folderBrowser.ShowNewFolderButton = true;

                    owner.WindowState = FormWindowState.Minimized;
                    owner.Show();
                    owner.WindowState = FormWindowState.Normal;

                    if (folderBrowser.ShowDialog(this) == DialogResult.OK)
                    {
                        ws.Send("Browser|UpdateInstallLocation|" + folderBrowser.SelectedPath);
                        installDirectory = folderBrowser.SelectedPath;
                    }
                }
            });
        }
示例#4
0
 // Gets current IP
 public static string getExternalIP()
 {
     return(JsonObject.readFrom(ScarletAPI.Request("", "", "", "")).get("ip").asString());
 }
示例#5
0
        public void Scarlet_WS_Initialise()
        {
            /* Scarlet Metrics */
            wsm = new ScarletMetrics();
            wsm.Send("Scarlet Service Started. (" + ip + ")");

            /* Server */
            var wssv = new WebSocketServer("ws://" + scarletAgentURL + ":" + scarletAgentPort);

            wssv.AddWebSocketService <Link>("/");
            wssv.Start();

            /* Client */
            ws = new WebSocket("ws://" + scarletAgentURL + ":" + scarletAgentPort);

            ws.Connect();

            ws.OnOpen += (sender, e) =>
            {
                ws.Send("Browser|Connected");
            };

            ws.OnMessage += (sender, e) =>
            {
                // Scarlet WS API
                // Words = (Browser/Updater)|(IP/*)|(Command)|(Perameters)
                string[] words = e.Data.Split('|');
                if (words[0] == "Updater")
                {
                    switch (words[1])
                    {
                    case ("browserConnect"):
                        Username = words[2];
                        key      = ScarletAPI.Request("user", "info", words[2]);

                        if (backgroundWorker1.IsBusy == false)
                        {
                            ws.Send("Browser|browserConfirmation|free");
                        }
                        else
                        {
                            ws.Send("Browser|browserConfirmation|busy");
                        }
                        break;

                    case ("startDownload"):

                        installDirectory = words[2];
                        if (backgroundWorker1.IsBusy == false)
                        {
                            backgroundWorker1.RunWorkerAsync();
                        }
                        break;

                    case ("startVerify"):

                        verifyOnly       = true;
                        installDirectory = words[2];
                        if (backgroundWorker1.IsBusy == false)
                        {
                            backgroundWorker1.RunWorkerAsync();
                        }
                        break;

                    case ("stopDownload"):

                        backgroundWorker1.CancelAsync();
                        ws.Send("Browser|browserConfirmation|free");
                        break;

                    case ("locationChange"):

                        ChooseFolder();

                        break;

                    case ("updateInstallLocation"):

                        installDirectory = words[2];
                        break;

                    case ("broadcast"):
                        broadcast(words[3]);
                        break;

                    case ("fetchStatus"):

                        pushStatusToBrowser();
                        break;

                    case ("quit"):

                        Application.Exit();
                        break;

                    case ("restart"):

                        Program.restarting = true;
                        Application.Restart();
                        break;
                    }
                }
            };

            ws.OnClose += (sender, e) =>
            {
                ws.Connect();
            };
        }