Beispiel #1
0
 private void ApplyOverwriteStrategy(OverwriteStrategy strategy, ExtractFileInfo[] existedFiles)
 {
     foreach (var fileInfo in existedFiles)
     {
         fileInfo.ShouldOverwrite = strategy == OverwriteStrategy.Overwrite;
     }
 }
Beispiel #2
0
 public ExtractPackageContentAction(string[] fileList,
                                    string destination,
                                    OverwriteStrategy overwriteStrategy = OverwriteStrategy.Ask)
 {
     this.FileList          = fileList;
     this.Destination       = destination;
     this.OverwriteStrategy = overwriteStrategy;
     this.UseRelativePath   = false;
 }
Beispiel #3
0
        public void Extract(string packagePath,
                            string localPath,
                            string destination,
                            OverwriteStrategy overwriteStrategy = OverwriteStrategy.Ask,
                            bool useRelativePath = true)
        {
            var action = new ExtractPackageContentAction(packagePath, localPath, destination, overwriteStrategy, useRelativePath);

            action.BeginAsync();
        }
Beispiel #4
0
        public ExtractPackageContentAction(string packagePath,
                                           string localPath,
                                           string destination,
                                           OverwriteStrategy overwriteStrategy = OverwriteStrategy.Ask,
                                           bool useRelativePath = true)
        {
            if (!File.Exists(packagePath))
            {
                throw new ArgumentException("packagePath", "invalid package path");
            }

            this.PackagePath       = packagePath;
            this.LocalPath         = localPath.Replace('\\', '/');
            this.Destination       = destination;
            this.OverwriteStrategy = overwriteStrategy;
            this.UseRelativePath   = useRelativePath;
        }
Beispiel #5
0
        private void CheckForFirstArchiveInstall(ZipArchive archive)
        {
            int numExisting = 0;
            int numReadOnly = archive.Entries
                              .Where(NotFiltered)
                              .Select(entry => CheckExpectedReadonly(ref numExisting, entry))
                              .Where(path => path != null)
                              .Count(IsReadOnly);

            if (numExisting == 0 || numReadOnly >= numExisting * 0.9)
            {
                return;
            }

            // have never used an archive before, so our files are not marked read only, we should probably replace all of them
            Option overwrite = new Option
            {
                Description = "Overwrite existing files with fresh versions from archive"
            };
            Choice choice = new Choice
            {
                Message =
                    "It seems like some files included in the current archive were previously installed without using an archive, such as by copying.  Please make sure you have saved any of these files you may have changed (this is not common) and choose one of the following:",
                Options = new List <Option>
                {
                    overwrite,
                    new Option
                    {
                        Description = "Leave all existing files alone, because you modified them intentionally"
                    }
                }
            };

            if (overwrite == PresentChoice(choice))
            {
                _defaultOverwriteStrategy = OverwriteStrategy.Always;
            }
        }
Beispiel #6
0
        private bool ResolveArchiveEntry(ZipArchiveEntry entry, out string unpackedPath,
                                         out OverwriteStrategy overwriteStrategy, out bool isProfile)
        {
            if (!GetPathSegments(entry, out List <string> pathSegments))
            {
                unpackedPath      = null;
                overwriteStrategy = OverwriteStrategy.Never;
                isProfile         = false;
                return(false);
            }

            if (pathSegments[1].Equals("Profiles", StringComparison.InvariantCultureIgnoreCase))
            {
                // install a profile
                string profileFileName = pathSegments[2];
                unpackedPath      = Path.Combine(ConfigManager.DocumentPath, "Profiles", profileFileName);
                overwriteStrategy = OverwriteStrategy.Never;
                isProfile         = true;
            }
            else
            {
                // install another type of file
                string relativePath = string.Join(Path.DirectorySeparatorChar.ToString(), pathSegments.Skip(1));
                unpackedPath = Path.Combine(ConfigManager.DocumentPath, relativePath);
                string unpackedDirectory = Path.GetDirectoryName(unpackedPath);
                if (null != unpackedDirectory && !Directory.Exists(unpackedDirectory))
                {
                    Directory.CreateDirectory(unpackedDirectory);
                }

                overwriteStrategy = _defaultOverwriteStrategy;
                isProfile         = false;
            }

            return(true);
        }
Beispiel #7
0
 public void WriteUsingOverwriteStrategy()
 {
     OverwriteStrategy.Write(this);
 }
Beispiel #8
0
        public void Extract(string[] fileList, string destination, OverwriteStrategy overwriteStrategy = OverwriteStrategy.Ask)
        {
            var action = new ExtractPackageContentAction(fileList, destination, overwriteStrategy);

            action.BeginAsync();
        }