Exemplo n.º 1
0
        /// <summary>
        /// Installs all files packaged in the installer to the local device
        /// </summary>
        public void InstallFiles()
        {
            m_failedFiles = 0;

            // get the list of target directories
            string[] directoryList = this.GetDirectories();

            // extract the files
            foreach (InstallerFile file in m_descriptor.Files)
            {
                // This is *not* physical number - don't be fooled by any docs that say it is
                FileInfo info = GetFileByExtensionIndex(file.ID);

                // copy the string so derived classes can alter them
                string targetFolder = string.Copy(m_descriptor.GetDirectoryByID(file.DirectoryID).GetString(m_descriptor.Strings));
                targetFolder = ReplaceSpecialFolderStrings(targetFolder);
                targetFolder = targetFolder.Replace("\\\\", "\\");

                string targetFile = string.Copy(file.FileName);

                FileInstallInfo installInfo = null;
                try
                {
                    lock (m_fileSyncRoot)
                    {
                        m_installInfo = info;
                        bool skipped;

                        installInfo = new FileInstallInfo(targetFile, targetFolder, file.Flags, info.FileDate);

                        OnInstallFile(ref installInfo, out skipped);
                    }
                }
                catch (Exception ex)
                {
                    if (FileFailure != null)
                    {
                        bool cancel = false;

                        FileFailure(installInfo, ex, ref cancel);
                        if (!cancel)
                        {
                            m_failedFiles++;
                        }
                    }
                    else
                    {
                        m_failedFiles++;
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called when a file is extracted from the installer and needs to be installed to the device OS
        /// </summary>
        /// <param name="fileInfo"></param>
        /// <param name="skipped"></param>
        public virtual void OnInstallFile(ref FileInstallInfo fileInfo, out bool skipped)
        {
            skipped = false;

            string destFile = SI.Path.Combine(fileInfo.DestinationFolder, fileInfo.FileName);

            if (((fileInfo.Flags & FileFlags.DoNotOverwrite) == FileFlags.DoNotOverwrite) &&
                (SI.File.Exists(destFile)))
            {
                skipped = true;
                return;
            }

            if (((fileInfo.Flags & FileFlags.OnlyCopyExisting) == FileFlags.OnlyCopyExisting) &&
                (!SI.File.Exists(destFile)))
            {
                skipped = true;
                return;
            }

            if (((fileInfo.Flags & FileFlags.OverwriteIfNewer) == FileFlags.OverwriteIfNewer) &&
                (SI.File.Exists(destFile)))
            {
                SI.FileInfo destInfo = new System.IO.FileInfo(destFile);
                if (destInfo.CreationTime > fileInfo.FileDate)
                {
                    skipped = true;
                    return;
                }
            }

            if (SI.File.Exists(destFile))
            {
                SI.File.Delete(destFile);
            }

            if (!SI.Directory.Exists(fileInfo.DestinationFolder))
            {
                SI.Directory.CreateDirectory(fileInfo.DestinationFolder);
            }

            SI.File.Copy(SI.Path.Combine(m_tempFolder, m_installInfo.Name), destFile);
        }