Esempio n. 1
0
        public static List <Package> GetPackages()
        {
            packages = new List <Package>();
            if (!Directory.Exists("packages\\"))
            {
                Directory.CreateDirectory("packages");
            }

            foreach (string st in Directory.GetFiles("packages\\", "*.zip", SearchOption.AllDirectories))
            {
                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);
                    }

                    if (!p.Enabled)
                    {
                        InstallPackage(p);
                    }
                }
            }

            return(packages);
        }
Esempio n. 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)
                                        {
                                            Console.WriteLine(e.Message);
                                        }
                                        break;

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

                                        // TODO: Copy the file to a temp directory
                                        Directory.CreateDirectory("tmp");
                                        var tmp = Path.Combine("tmp", entry.Name);
                                        try
                                        {
                                            entry.ExtractToFile(tmp);
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine(e.Message);
                                        }

                                        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);
                    }
                    else
                    {
                        // No product thingy
                    }
                }
            }
            return(false);
        }