Exemplo n.º 1
0
        protected override void OnExit(ExitEventArgs e)
        {
            base.OnExit(e);
            LuaScripting.CloseScripts();

            // Abort all threads
            if (_luaThread != null && _luaThread.IsAlive)
            {
                _luaThread.Abort();
            }

            if (Server._clientThread != null && Server._clientThread.IsAlive)
            {
                Server._clientThread.Abort();
            }

            if (_serverThread != null && _serverThread.IsAlive)
            {
                _serverThread.Abort();
            }
        }
Exemplo n.º 2
0
        private static void ParseData(TcpClient listener)
        {
            // Buffer for reading data
            Byte[] bytes = new Byte[256];

            try
            {
                // Enter the listening loop.


                // Perform a blocking call to accept requests.
                // You could also user server.AcceptSocket() here.



                // Get a stream object for reading and writing
                NetworkStream stream = listener.GetStream();


                byte[]        myReadBuffer      = new byte[1024];
                StringBuilder myCompleteMessage = new StringBuilder();
                int           numberOfBytesRead = 0;

                // Incoming message may be larger than the buffer size.
                do
                {
                    numberOfBytesRead = stream.Read(myReadBuffer, 0, myReadBuffer.Length);

                    myCompleteMessage.AppendFormat("{0}", Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead));
                }while (stream.DataAvailable);
                if (myCompleteMessage.Length != 0)
                {
                    // Print out the received message to the console.
                    try
                    {
                        var split = myCompleteMessage.ToString().Split(new char[] { '{' }, 2);

                        if (split.Length > 1)
                        {
                            String ns = "{" + myCompleteMessage.ToString().Split(new char[] { '{' }, 2)[1];
                            myCompleteMessage = null;
                            //Debug.Write(myCompleteMessage);
                            string header = string.Format("HTTP/1.1 {0}\r\n"
                                                          + "Server: {1}\r\n"
                                                          + "Content-Type: {2}\r\n"
                                                          + "Keep-Alive: Close\r\n"
                                                          + "\r\n",
                                                          "HTTP 200 OK", "Chroma Sync", "application/json");
                            // Send header & data
                            var headerBytes = Encoding.ASCII.GetBytes(header);
                            stream.Write(headerBytes, 0, headerBytes.Length);

                            try
                            {
                                JObject o = JObject.Parse(ns);
                                LuaScripting.PassThrough(o);
                            }
                            catch { }
                        }
                    }
                    catch (Exception e)
                    {
                        App.Log.Error(e);
                    }
                }
            }
            catch (Exception e)
            {
                App.Log.Error(e);
            }
            finally
            {
                try
                {
                    listener.Close();
                }
                catch { }
            }
        }
Exemplo n.º 3
0
 static void ReloadScripts(object sender, EventArgs e)
 {
     LuaScripting.ReloadScripts();
 }
Exemplo n.º 4
0
 private void Uninit(object sender, EventArgs e)
 {
     LuaScripting.CloseScripts();
     Debug.WriteLine(Chroma.Instance.Initialized);
 }
Exemplo n.º 5
0
        public static bool RemovePackage(Package p)
        {
            var message = MessageBox.Show("Are you sure you would like to remove the package " + p.Product.Name + "?", "Chroma Sync: " + p.Product.Name,
                                          MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (message == DialogResult.No)
            {
                return(false);
            }

            LuaScripting.CloseScripts();
            foreach (var step in p.Installation)
            {
                using (ZipArchive archive = ZipFile.OpenRead(p.Container))
                {
                    if (p.Product.Name != null)
                    {
                        foreach (ZipArchiveEntry entry in archive.Entries)
                        {
                            if (step.Folder != null)
                            {
                                if (entry.FullName.StartsWith(step.Folder, StringComparison.OrdinalIgnoreCase) && entry.Name.Length > 0)
                                {
                                    switch (step.Action)
                                    {
                                    case "extract":
                                        var path = step.Destination.Folder;
                                        path = Environment.ExpandEnvironmentVariables(path);
                                        Console.WriteLine(entry.FullName);
                                        if (step.Destination.Type == "steamapp")
                                        {
                                            var steamFolder = GameLocator.InstallFolder(step.Destination.Folder);
                                            if (steamFolder == null)
                                            {
                                                Console.WriteLine("Could not find steam folder: " + steamFolder);
                                                return(false);
                                            }
                                            path = steamFolder;
                                        }
                                        var sp = entry.FullName.Remove(0, step.Folder.Length + 1);
                                        var pa = Path.Combine(path, sp);

                                        try
                                        {
                                            File.Delete(pa);
                                        }
                                        catch (Exception e)
                                        {
                                            App.Log.Error(e);
                                        }
                                        break;

                                    case "execute":
                                        if (!entry.Name.Equals(step.File))
                                        {
                                            continue;
                                        }


                                        var tmp = Path.Combine("tmp", entry.Name);
                                        try
                                        {
                                            File.Delete(tmp);
                                        }
                                        catch (Exception e)
                                        {
                                            App.Log.Error(e);
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            try
            {
                File.Delete(p.Container);
                RegistryKeeper.UpdateReg(p.Container, "");
                GetPackages();
                LuaScripting.ReloadScripts();
                return(true);
            }
            catch (Exception e)
            {
                App.Log.Error(e);
            }

            return(false);
        }
Exemplo n.º 6
0
        public static bool InstallPackage(Package p)
        {
            var message = MessageBox.Show("Would you like to install the package " + p.Product.Name + "?", "Chroma Sync: " + p.Product.Name,
                                          MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (message == DialogResult.No)
            {
                return(false);
            }
            foreach (var step in p.Installation)
            {
                using (ZipArchive archive = ZipFile.OpenRead(p.Container))
                {
                    if (p.Product.Name != null)
                    {
                        foreach (ZipArchiveEntry entry in archive.Entries)
                        {
                            if (step.Folder != null)
                            {
                                if (entry.FullName.StartsWith(step.Folder, StringComparison.OrdinalIgnoreCase) && entry.Name.Length > 0)
                                {
                                    switch (step.Action)
                                    {
                                    case "extract":
                                        var path = step.Destination.Folder;
                                        path = Environment.ExpandEnvironmentVariables(path);
                                        Console.WriteLine(entry.FullName);
                                        if (step.Destination.Type == "steamapp")
                                        {
                                            var steamFolder = GameLocator.InstallFolder(step.Destination.Folder);
                                            if (steamFolder == null)
                                            {
                                                Console.WriteLine("Could not find steam folder: " + steamFolder);
                                                return(false);
                                            }
                                            path = steamFolder;
                                        }
                                        var sp = entry.FullName.Remove(0, step.Folder.Length + 1);
                                        var pa = Path.Combine(path, sp);
                                        if (!Directory.Exists(path))
                                        {
                                            Directory.CreateDirectory(path);
                                        }

                                        try
                                        {
                                            entry.ExtractToFile(pa, true);
                                        }
                                        catch (Exception e)
                                        {
                                            App.Log.Error(e);
                                        }
                                        break;

                                    case "execute":
                                        if (!entry.Name.Equals(step.File))
                                        {
                                            continue;
                                        }

                                        if (step.Description != null)
                                        {
                                            message = MessageBox.Show(step.Description, "Chroma Sync: " + p.Product.Name,
                                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                        }
                                        else
                                        {
                                            message = MessageBox.Show("The following file needs to be installed: " + step.File + ". Would you like to continue?", "Chroma Sync: " + p.Product.Name,
                                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                        }

                                        if (message == DialogResult.No)
                                        {
                                            return(false);
                                        }
                                        Directory.CreateDirectory("tmp");
                                        var tmp = Path.Combine("tmp", entry.Name);
                                        try
                                        {
                                            entry.ExtractToFile(tmp);
                                        }
                                        catch (Exception e)
                                        {
                                            App.Log.Error(e);
                                        }

                                        System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                                        System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                                        //startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                                        startInfo.FileName = entry.Name;
                                        // temp folder in the Chroma Sync directory
                                        startInfo.WorkingDirectory = "tmp";
                                        startInfo.Arguments        = step.Cmd;
                                        process.StartInfo          = startInfo;
                                        process.Start();
                                        process.WaitForExit();
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            RegistryKeeper.UpdateReg(p.Container, p.Product.Version);
            GetPackages();
            LuaScripting.ReloadScripts();
            return(true);
        }