Ejemplo n.º 1
0
        // TODO: The package should be mounted into its own context to avoid name collisions with installed files
        public static bool ExtractFromPackage(FileSystem.FileSystem fileSystem, string srcPath, string package, Dictionary<string, string[]> filesByDirectory,
			string destPath, bool overwrite, ContentInstaller.FilenameCase caseModifier, Action<string> onProgress, Action<string> onError)
        {
            Directory.CreateDirectory(destPath);

            Log.Write("debug", "Mounting {0}".F(srcPath));
            fileSystem.Mount(srcPath);
            Log.Write("debug", "Mounting {0}".F(package));
            fileSystem.Mount(package);

            foreach (var directory in filesByDirectory)
            {
                var targetDir = directory.Key;

                foreach (var file in directory.Value)
                {
                    var containingDir = Path.Combine(destPath, targetDir);
                    var dest = Path.Combine(containingDir, GetFileName(file, caseModifier));
                    if (File.Exists(dest))
                    {
                        if (overwrite)
                            File.Delete(dest);
                        else
                        {
                            Log.Write("debug", "Skipping {0}".F(dest));
                            continue;
                        }
                    }

                    Directory.CreateDirectory(containingDir);

                    using (var sourceStream = fileSystem.Open(file))
                    using (var destStream = File.Create(dest))
                    {
                        Log.Write("debug", "Extracting {0} to {1}".F(file, dest));
                        onProgress("Extracting " + file);
                        destStream.Write(sourceStream.ReadAllBytes());
                    }
                }
            }

            return true;
        }
Ejemplo n.º 2
0
        public static bool CopyFiles(string srcPath, Dictionary<string, string[]> files, string destPath,
			bool overwrite, ContentInstaller.FilenameCase caseModifier, Action<string> onProgress, Action<string> onError)
        {
            Directory.CreateDirectory(destPath);

            foreach (var folder in files)
            {
                var targetDir = folder.Key;

                foreach (var file in folder.Value)
                {
                    var sourcePath = Path.Combine(srcPath, file);
                    if (!File.Exists(sourcePath))
                    {
                        onError("Cannot find " + file);
                        return false;
                    }

                    var destFile = GetFileName(file, caseModifier);
                    var containingDir = Path.Combine(destPath, targetDir);
                    var dest = Path.Combine(containingDir, destFile);
                    if (File.Exists(dest) && !overwrite)
                    {
                        Log.Write("debug", "Skipping {0}".F(dest));
                        continue;
                    }

                    Directory.CreateDirectory(containingDir);

                    onProgress("Copying " + destFile);
                    Log.Write("debug", "Copy {0} to {1}".F(sourcePath, dest));
                    File.Copy(sourcePath, dest, true);
                }
            }

            return true;
        }
Ejemplo n.º 3
0
        static string GetFileName(string path, ContentInstaller.FilenameCase caseModifier)
        {
            // Gets the file path, splitting on both / and \
            var index = path.LastIndexOfAny(new[] { '\\', '/' });
            var output = path.Substring(index + 1);

            switch (caseModifier)
            {
                case ContentInstaller.FilenameCase.ForceLower:
                    return output.ToLowerInvariant();
                case ContentInstaller.FilenameCase.ForceUpper:
                    return output.ToUpperInvariant();
                default:
                    return output;
            }
        }