示例#1
0
        public static InstallOption Deserialize(InstallerBinary binary)
        {
            string key   = binary.ReadUTF8Path();
            string value = binary.ReadUTF8Path();

            return(new InstallOption(key, value));
        }
示例#2
0
        public void LoadOptions()
        {
            Globals.Logger.LogInfo("Extracting Install Options");

            //Use a dummy to get the options table.
            InstallerBinary dummy = new InstallerBinary();

            _objOptions = new InstallOptions();

            try
            {
                dummy.OpenStream();
                _objOptions.Deserialize(dummy);
            }
            catch (Exception ex)
            {
                Globals.Logger.LogInfo("Exception opening install options: " + ex.ToString());

                throw ex;
            }
            finally
            {
                dummy.CloseStream();
            }

            dummy = null;
        }
示例#3
0
        private void UnpackFile(InstallerBinary objBinary, FileTableEntry entry, ref string strCurrentFileName)
        {
            string strFilePath = entry.Path;

            strFilePath = _objManager.ReplaceValueVariables(strFilePath);

            strCurrentFileName = strFilePath;

            if (System.IO.File.Exists(strFilePath))
            {
                Globals.Logger.LogInfo("Overwriting " + strFilePath);
            }

            string dirname = System.IO.Path.GetDirectoryName(strFilePath);

            if (!System.IO.Directory.Exists(dirname))
            {
                Globals.Logger.LogInfo("Creating " + dirname);
                System.IO.Directory.CreateDirectory(dirname);
            }

            byte[] fileBytes = objBinary.ReadFileBytes(entry);

            Globals.Logger.LogInfo("Writing File " + strFilePath);

            FileUtils.WriteBytesViaStream(strFilePath, fileBytes);

            // System.IO.File.WriteAllBytes(strFilePath, fileBytes);

            // InstalledFiles.Add(strFilePath);
        }
示例#4
0
        public void UnpackFiles(InstallerBinary objBinary, string strInstallRoot,
                                ref double dblProgress, System.Threading.CancellationToken token, ref string strCurrentFile)
        {
            if (!System.IO.Directory.Exists(strInstallRoot))
            {
                System.IO.Directory.CreateDirectory(strInstallRoot);
            }

            double dblInitialProgress = dblProgress;

            // Unpack all files.
            for (int iEntry = 0; iEntry < _lstEntries.Count; iEntry++)
            {
                FileTableEntry entry = _lstEntries[iEntry];

                UnpackFile(objBinary, entry, ref strCurrentFile);

                dblProgress = dblInitialProgress + ((double)iEntry / (double)_lstEntries.Count * (1.0 - dblInitialProgress));

                if (token.IsCancellationRequested)
                {
                    token.ThrowIfCancellationRequested();
                }
            }
        }
 private void BuildPostfixedBinary(BuildForm bf)
 {
     byte[] temp;
     bf.DetailMessage("Building Binary.");
     temp   = InstallerBinary.GetBytes();
     _final = BufferUtils.Combine(_final, temp);
     Globals.Logger.LogInfo("Binary:" + temp.Length.ToString() + "B Total:" + _final.Length.ToString() + "B");
     bf.Progress(0.03);
 }
示例#6
0
        public static FileTableEntry Deserialize(InstallerBinary objBinary)
        {
            Int64          off  = objBinary.ReadInt64();
            Int64          size = objBinary.ReadInt64();
            string         path = objBinary.ReadUTF8Path();
            FileTableEntry ret  = new FileTableEntry(off, size, path);

            return(ret);
        }
示例#7
0
        public void Deserialize(InstallerBinary objBinary)
        {
            Int64 count = objBinary.ReadInt64();

            for (Int64 iOption = 0; iOption < count; iOption++)
            {
                InstallOption opt = InstallOption.Deserialize(objBinary);
                _lstInstallOptions.Add(opt);
            }
        }
示例#8
0
        public void Deserialize(InstallerBinary objBinary)
        {
            Int64 entries = objBinary.ReadInt64();

            for (Int64 iEntry = 0; iEntry < entries; iEntry++)
            {
                FileTableEntry ent = FileTableEntry.Deserialize(objBinary);
                _lstEntries.Add(ent);
            }
        }
示例#9
0
        private void CreateUninstaller(ProgramInfo objProgramInfo, InstallerBinary objBinary, InstallerFileTable objTable, string strInstallRoot)
        {
            string strUninstallExePath;

            Globals.Logger.LogInfo("Creating Uninstaller");

            //Add the root to the options.
            _objOptions.AddOrReplaceOption(new InstallOption(InstallOption.UninstallFolderRoot_Uninstaller_Only, strInstallRoot));

            strUninstallExePath = objTable.WriteUninstaller(_objOptions, strInstallRoot);

            WriteUninstallerRegistryKeys(objProgramInfo, strUninstallExePath, strInstallRoot);
        }
示例#10
0
        private void ExecuteUninstall()
        {
            InstallerFileTable objTable   = null;
            InstallerBinary    objBinary  = null;
            InstallOptions     objOptions = null;

            InstallState = Installer.InstallState.Uninstalling;

            //TODO: uninstaller has to store options AND uninstall table.
            try
            {
                objBinary = new InstallerBinary();
                objBinary.OpenStream();
                objOptions = new InstallOptions();
                objOptions.Deserialize(objBinary);
                objTable = new InstallerFileTable(this);
                objTable.Deserialize(objBinary);
                objBinary.CloseStream();

                ProgramInfo objInfo = new ProgramInfo(objOptions);

                string strInstallRoot = objOptions.GetOptionValueOrDefault(InstallOption.UninstallFolderRoot_Uninstaller_Only);
                if (!System.IO.Directory.Exists(strInstallRoot))
                {
                    Globals.Logger.LogError("Fatal Error: The original install directory '"
                                            + strInstallRoot
                                            + "' does not exist, or was not packed in the uninstaller binary.", true, true);
                }

                RollbackOrUninstall(objTable, strInstallRoot, 0.0);

                RemoveRegistryKeys(objInfo);

                InstallState = Installer.InstallState.Successful;
            }
            catch (Exception ex)
            {
                InstallState = Installer.InstallState.Canceled;
                InstallErrors.Add("Error: " + ex.ToString());
                Globals.Logger.LogError(ex.ToString(), false, true);
            }
            finally
            {
                EndUninstall();
            }
        }
        /*
         * See InstallerManager for file format.
         *
         */
        public void BuildUninstaller(InstallerFileTable ft, InstallOptions opt, string outputFileName)
        {
            //**Do not modify the filename.
            InstallerBinary objBinary = new InstallerBinary();

            objBinary.OpenStream();
            objBinary.CloseStream();

            byte[] temp;
            temp   = objBinary.GetInstallerBinary();
            _final = BufferUtils.Combine(_final, temp);
            temp   = InstallerBinary.GetTokenBytes();
            _final = BufferUtils.Combine(_final, temp);
            temp   = opt.Serialize();
            _final = BufferUtils.Combine(_final, temp);
            temp   = ft.Serialize(); // ** Ft is already built.  Do not call Build()
            _final = BufferUtils.Combine(_final, temp);

            FileUtils.WriteBytesViaStream(outputFileName, _final);
        }
示例#12
0
        private void ExecuteInstallation()
        {
            DisplayMsg("Beginning Installation");
            InstallState = InstallState.Installing;
            InstallerFileTable objTable = null;

            string strInstallRoot = CreateInstallRoot();

            if (string.IsNullOrEmpty(strInstallRoot))
            {
                return; // error
            }
            double dblProgressBeforeCopy = 0;

            try
            {
                DisplayMsg("Creating install dir " + strInstallRoot);
                if (!System.IO.Directory.Exists(strInstallRoot))
                {
                    System.IO.Directory.CreateDirectory(strInstallRoot);
                }

                // - Do work
                InstallerBinary objBinary;
                DisplayMsg("Creating binary");
                objBinary = new InstallerBinary();
                objBinary.OpenStream();

                //**Read past the install options section.  Note this
                // is NOT used
                DisplayMsg("Reading Dummy Options");
                InstallOptions dummy = new InstallOptions();
                dummy.Deserialize(objBinary);

                //Validate appliation GUID for uninstall.
                InstallOption guidOpt = GetOption(InstallOption.AppGuid);
                if (guidOpt == null)
                {
                    Globals.Throw("Could not install.  Appliation GUID was not specified in install options.");
                }
                else
                {
                    ProgramInfo.TryParseGuidToUninstallGuid(guidOpt.Value);
                }

                DisplayMsg("Creating Program Info");
                ProgramInfo objInfo = new ProgramInfo(_objOptions);

                DisplayMsg("Reading File Table");
                objTable = new InstallerFileTable(this);
                objTable.Deserialize(objBinary);

                _dblProgress = dblProgressBeforeCopy = 0.5;

                DisplayMsg("Unpacking Files");
                objTable.UnpackFiles(
                    objBinary,
                    strInstallRoot,
                    ref _dblProgress,
                    _installerCancellationToken.Token,
                    ref _strCurrentFile
                    );

                objBinary.CloseStream();

                CreateAppRegistryKeys(objInfo, strInstallRoot);
                CreateUninstaller(objInfo, objBinary, objTable, strInstallRoot);
            }
            catch (Exception ex)
            {
                InstallState = Installer.InstallState.Canceled;
                InstallErrors.Add("Error: " + ex.ToString());
                Globals.Logger.LogError(ex.ToString(), false, true);
                RollbackOrUninstall(objTable, strInstallRoot, dblProgressBeforeCopy);
            }
            finally
            {
                EndInstallation();
            }
        }