Пример #1
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);
        }
Пример #2
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);
        }