示例#1
0
        private static bool SetupConfiguration(CommandParser commandParser)
        {
            if (commandParser.Has("destination", "template", "setupName", "mainapplication"))
            {
                using (RegistryKey parent = Registry.CurrentUser.OpenSubKey(
                                     @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true))
                {
                    if (parent == null)
                    {
                        Console.WriteLine("Uninstall registry key not found.");
                        return false;
                    }
                    try
                    {
                        string guidText = commandParser["setupName"];
                        if (parent.OpenSubKey(guidText, true) != null)
                        {
                            Console.WriteLine("First uninstall '{0}'", guidText);
                            return false;
                        }
                    }
                    catch
                    {
                    }
                }
                Console.WriteLine("Setting up on {0}", commandParser["destination"]);
                Console.WriteLine("");
                string pluginDirs = null;
                if (commandParser.IsSet("plugins"))
                {
                    pluginDirs = commandParser["plugins"];
                }
                string rollbackPath = Path.Combine(commandParser["destination"], "rollaback.ser");
                if (commandParser.IsSet("rollback"))
                {
                    rollbackPath = commandParser["rollback"];
                }
                var unattended = commandParser.IsSet("unattended");

                string sourcePath = null;
                if (commandParser.IsSet("source"))
                {
                    sourcePath = commandParser["source"];
                }
                if (SetupLoader.Start(commandParser["template"], commandParser["destination"], pluginDirs, unattended,
                                                            rollbackPath,sourcePath))
                {
                    CreateUninstaller(commandParser["destination"], rollbackPath, commandParser["setupName"],
                        commandParser["mainapplication"]);
                }
            }
            return true;
        }
示例#2
0
        static void Main(string[] args)
        {
            FileDescriptor temporaryManifestedExecutable = null;
            var cp = new CommandParser(args, HELP);
            if (cp.Has("setup", "application", "outcome", "script", "mainapplication"))
            {
                if (cp.IsSet("mt"))
                {
                    _mtExePath = cp["mt"];
                }
                var starterScript = Path.GetFullPath(cp["script"]);
                var setupDir = Path.GetFullPath(cp["setup"]);
                var applicationDir = Path.GetFullPath(cp["application"]);
                var applicationDirPlugins = Path.Combine(Path.GetFullPath(cp["application"]), "Plugins");
                var outcomeFile = Path.GetFullPath(cp["outcome"]);
                var setupCoreDir = Path.Combine(setupDir, "Core");
                var setupPackagerDir = Path.Combine(setupDir, "Packager");
                var setupRunnerDir = Path.Combine(setupDir, "Runner");
                var setupPluginsDir = Path.Combine(setupDir, "Plugins");

                var tmpPath = Path.GetTempPath();
                var tmpDirectory = Path.Combine(tmpPath, Guid.NewGuid().ToString());
                Directory.CreateDirectory(tmpDirectory);

                try
                {
                    var filesToAdd = new List<FileDescriptor>();
                    var pluginsDirs = new List<string>();

                    //Load application plugins
                    if (Directory.Exists(applicationDirPlugins))
                    {
                        pluginsDirs.Add(applicationDirPlugins);
                        var applicationPlugins = Directory.GetDirectories(applicationDirPlugins, "*.*", SearchOption.TopDirectoryOnly);

                        foreach (var singlePluginDir in applicationPlugins)
                        {
                            var plugin = Path.GetFileName(singlePluginDir);
                            filesToAdd.AddRange(SetupFileDescriptors(
                                singlePluginDir,
                                "plugins" + Path.DirectorySeparatorChar + plugin,
                                Directory.GetFiles(singlePluginDir, "*.*", SearchOption.AllDirectories)));
                        }
                    }

                    if (cp.IsSet("plugins"))
                    {
                        var pluginString = cp["plugins"];
                        var plugins = pluginString.Split(';');
                        foreach (var plugin in plugins)
                        {
                            var singlePluginDir = Path.Combine(setupPluginsDir, plugin);
                            pluginsDirs.Add(singlePluginDir);
                            filesToAdd.AddRange(SetupFileDescriptors(
                                singlePluginDir,
                                "plugins" + Path.DirectorySeparatorChar + plugin,
                                Directory.GetFiles(singlePluginDir, "*.*", SearchOption.AllDirectories)));
                        }
                    }

                    var manifestNeeded = CheckManifestNeed(pluginsDirs);

                    filesToAdd.AddRange(SetupFileDescriptors(
                        applicationDir,
                        "application",
                        Directory.GetFiles(cp["application"], "*.*", SearchOption.AllDirectories)));

                    filesToAdd.AddRange(SetupFileDescriptors(
                        setupCoreDir,
                        "setup",
                        Directory.GetFiles(setupCoreDir, "*.*", SearchOption.AllDirectories)));

                    if (manifestNeeded > 0)
                    {
                        var removedSetup = RemoveSetupExeFromFileList(filesToAdd);
                        temporaryManifestedExecutable = AddNewManifestedSetupExe(removedSetup, filesToAdd, manifestNeeded);
                        filesToAdd.Add(temporaryManifestedExecutable);
                    }

                    var zipArchive = Path.Combine(tmpDirectory, "SetupContent.zip");
                    using (var zip = new ZipFile())
                    {
                        for (int i = 0; i < filesToAdd.Count; i++)
                        {
                            var item = filesToAdd[i];
                            zip.AddFile(item.SourcePath).FileName = item.ZipPath;
                        }
                        zip.Save(zipArchive);
                        Console.WriteLine("Created temporary archive.");
                    }

                    var setupZipDll = Path.Combine(setupPackagerDir, "Ionic.Zip.dll");
                    var runnerExecutable = Path.Combine(setupRunnerDir, "Zak.Setup.Runner.exe");

                    var runnerExecutableBytes = File.ReadAllBytes(runnerExecutable);
                    var zipDllBytes = File.ReadAllBytes(setupZipDll);
                    var scriptBytes = File.ReadAllBytes(starterScript);
                    var contentArchiveBytes = File.ReadAllBytes(zipArchive);
                    var separator = ASCIIEncoding.ASCII.GetBytes("XXXTHISISTHESEPA@@@RATOR@@@ASFARASIKNOWSONO@@@PROBLEMXXX");

                    var extraParameters = ASCIIEncoding.ASCII.GetBytes(string.Format("mainapplication={0}\n", cp["mainapplication"]));

                    var ms = new MemoryStream();
                    ms.Write(runnerExecutableBytes, 0, runnerExecutableBytes.Length);
                    ms.Write(separator, 0, separator.Length);
                    ms.Write(zipDllBytes, 0, zipDllBytes.Length);
                    ms.Write(separator, 0, separator.Length);
                    ms.Write(contentArchiveBytes, 0, contentArchiveBytes.Length);
                    ms.Write(separator, 0, separator.Length);
                    ms.Write(scriptBytes, 0, scriptBytes.Length);
                    ms.Write(separator, 0, separator.Length);
                    ms.Write(extraParameters, 0, extraParameters.Length);
                    File.WriteAllBytes(outcomeFile, ms.ToArray());
                    Console.WriteLine("Written setup {0}.", outcomeFile);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error:\n{0}.", ex.ToString());
                    if (File.Exists(outcomeFile))
                    {
                        File.Delete(outcomeFile);
                    }
                }
                finally
                {
                    CleanUpDir(new DirectoryInfo(tmpDirectory));

                    if (temporaryManifestedExecutable != null)
                    {
                        File.Delete(temporaryManifestedExecutable.SourcePath);
                        File.Delete(temporaryManifestedExecutable.SourcePath+".Manifest");
                        Directory.Delete(Path.GetDirectoryName(temporaryManifestedExecutable.SourcePath));
                    }

                    Console.WriteLine("CleanedUp temporary files.");
                }
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            var commandParser = new CommandParser(args, HELP_MESSAGE);

            if (commandParser.Has("uninstall", "rollback", "installer"))
            {

                var unattended = commandParser.IsSet("unattended");
                var undoPath = commandParser["rollback"];
                var setupName = commandParser["installer"];
                string pluginDirs = null;
                if (commandParser.IsSet("plugins"))
                {
                    pluginDirs = commandParser["plugins"];
                }

                SetupLoader.Uninstall(undoPath, unattended, setupName, pluginDirs);

                if (commandParser.Has("cleaner", "destination"))
                {
                    var cleaner = commandParser["cleaner"];
                    var destination = commandParser["destination"];
                    var guid = commandParser["guid"];
                    LoadAndRunCleaner(cleaner, destination, commandParser.IsSet("unattended"), guid);
                }
            }
            else if (!SetupConfiguration(commandParser))
            {
                commandParser.ShowHelp();
            }
            if (!commandParser.IsSet("unattended"))
            {
                Console.ReadLine();
            }
        }