Ejemplo n.º 1
0
        public static List <Package> GetPackages()
        {
            packages = new List <Package>();
            App.NewPackagesContext();


            foreach (string st in Directory.GetFiles(AppPath, "*.csp", SearchOption.AllDirectories))
            {
                if (Path.GetFileName(st).StartsWith("."))
                {
                    continue;
                }
                Console.WriteLine("Found package:" + st);
                // Open the package for reading
                using (ZipArchive archive = ZipFile.OpenRead(st))
                {
                    var p = PackageDetails(archive);
                    p.Container = st;

                    var v = RegistryKeeper.GetValue(p.Container);
                    if (v == p.Product.Version)
                    {
                        p.Enabled = true;
                    }

                    if (p.Product.Name != null)
                    {
                        packages.Add(p);
                    }
                }
            }

            return(packages);
        }
Ejemplo n.º 2
0
        private static void MenuItem_Click(object sender, EventArgs e)
        {
            MenuItem s = (MenuItem)sender;

            RegistryKeeper.UpdateReg((string)s.Tag, (!s.Checked).ToString());
            ReloadScripts();
        }
Ejemplo n.º 3
0
        private void FirstRun()
        {
            // Check if first run
            int v = 0;

            try
            {
                v = int.Parse(RegistryKeeper.GetValue("lastversion"));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            if (CurrentBuild > v)
            {
                Intro iWindow = new Intro();
                iWindow.ShowDialog();
                RegistryKeeper.UpdateReg("lastversion", CurrentBuild.ToString());
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public static void LuaThread()
        {
            if (watcher == null)
            {
                Watch();
            }


            App.c = Chroma.Instance;
            App.c.Initialize();
            App.c.DeviceAccess += C_DeviceAccess;
            App.NewScriptsContext();
            // WE NEED TO ENSURE CHROMA IS INITIALISED
            callbacks = new List <dynamic>();

            var ms_luaDebug          = new LuaStackTraceDebugger();
            var ms_luaCompileOptions = new LuaCompileOptions();

            ms_luaCompileOptions.DebugEngine = ms_luaDebug;
            scriptThreads = new Collection <Thread>();

            string path = @"%appdata%\ChromaSync";

            path = Environment.ExpandEnvironmentVariables(path);

            string scriptsPath  = Path.Combine(path, "scripts");
            string packagesPath = Path.Combine(path, "packages");

            if (!Directory.Exists(scriptsPath))
            {
                Directory.CreateDirectory(scriptsPath);
            }


            // Todo: Get all scripts including the packages
            var files = Directory.GetFiles(path, "*.lua", SearchOption.AllDirectories);

            foreach (string st in files)
            {
                var      v        = RegistryKeeper.GetValue(st);
                MenuItem menuItem = new MenuItem(Path.GetFileName(st));
                menuItem.Name   = Path.GetFileName(st);
                menuItem.Tag    = st;
                menuItem.Click += MenuItem_Click;
                if (!st.Contains("\\ChromaSync\\packages\\"))
                {
                    App.scriptsMenu.MenuItems.Add(menuItem);
                }
                if (v.Equals("True"))
                {
                    menuItem.Checked = true;
                    scriptThreads.Add(
                        new Thread(() =>
                    {
                        using (Lua l = new Lua())
                        {
                            LuaGlobalPortable g = l.CreateEnvironment();
                            dynamic dg          = g;
                            dg.DebugLua         = new Func <object, bool>(debug);
                            dg.ConvertInt       = new Func <object, int>(convertInt);
                            dg.NewCustom        = new Func <string, Color, object>(newCustom);
                            dg.IntToByte        = new Func <int, byte>(IntToByte);
                            dg.Headset          = Headset.Instance;
                            dg.Keyboard         = Keyboard.Instance;
                            dg.Mouse            = Mouse.Instance;
                            dg.Keypad           = Keypad.Instance;
                            dg.Mousepad         = Mousepad.Instance;

                            dg.RegisterForEvents = new Func <string, object, bool>(registerEvents);
                            debug("starting Lua script: " + st);
                            try
                            {
                                LuaChunk compiled = l.CompileChunk(st, ms_luaCompileOptions);
                                var d             = g.DoChunk(compiled);
                            }
                            catch (LuaException e)
                            {
                                App.Log.Error(e);
                            }
                            catch (Exception e)
                            {
                                App.Log.Info(e);
                                Thread.ResetAbort();
                            }
                        }
                    }));
                    scriptThreads.Last().Start();
                }
            }
        }