Exemple #1
0
        public async Task TestDirectMatchIsIgnoredWhenGameFolderFilesOverrideExists()
        {
            var profile  = utils.AddProfile();
            var mod      = utils.AddMod();
            var test_pex = utils.AddGameFile(@"enbstuff\test.pex", 10);

            utils.Configure();

            Directory.CreateDirectory(Path.Combine(utils.MO2Folder, Consts.GameFolderFilesDir));

            utils.AddManualDownload(
                new Dictionary <string, byte[]> {
                { "/baz/biz.pex", File.ReadAllBytes(test_pex) }
            });

            await CompileAndInstall(profile);

            Assert.IsFalse(File.Exists(Path.Combine(utils.InstallFolder, Consts.GameFolderFilesDir, @"enbstuff\test.pex")));
        }
Exemple #2
0
            private async Task ExtractTrack(AbsolutePath source, AbsolutePath destFolder, Track track)
            {
                var process = new ProcessHelper
                {
                    Path      = FFMpegPath,
                    Arguments = new object[] { "-threads", 1, "-i", source, "-ss", track.Start, "-t", track.End - track.Start, track.Name.RelativeTo(destFolder).WithExtension(WAVExtension) },
                    ThrowOnNonZeroExitCode = true
                };

                var ffmpegLogs = process.Output.Where(arg => arg.Type == ProcessHelper.StreamType.Output)
                                 .ForEachAsync(val =>
                {
                    Utils.Status($"Extracting {track.Name} - {val.Line}");
                });

                await process.Start();

                if (track.Format == Track.FormatEnum.WAV)
                {
                    return;
                }

                process = new ProcessHelper()
                {
                    Path      = xWMAEncodePath,
                    Arguments = new object[] { "-b", 192000, track.Name.RelativeTo(destFolder).WithExtension(WAVExtension), track.Name.RelativeTo(destFolder).WithExtension(XWMExtension) },
                    ThrowOnNonZeroExitCode = true
                };

                var xwmLogs = process.Output.Where(arg => arg.Type == ProcessHelper.StreamType.Output)
                              .ForEachAsync(val =>
                {
                    Utils.Status($"Encoding {track.Name} - {val.Line}");
                });

                await process.Start();

                if (File.Exists($"{destFolder}\\{track.Name}.wav"))
                {
                    File.Delete($"{destFolder}\\{track.Name}.wav");
                }
            }
Exemple #3
0
        public static string ExtractToTempFile(GrepSearchResult searchResult)
        {
            if (searchResult == null)
            {
                throw new ArgumentNullException(nameof(searchResult));
            }

            string tempFolder = Path.Combine(Utils.GetTempFolder(), "dnGREP-Archive", Utils.GetHash(searchResult.FileNameReal));

            string[] parts = searchResult.FileNameDisplayed.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            if (!searchResult.FileNameDisplayed.Contains(ArchiveSeparator) || parts.Length < 2)
            {
                return(string.Empty);
            }
            string innerFileName = parts.Last();

            string[] intermediateFiles = parts.Skip(1).Take(parts.Length - 2).ToArray();
            string   filePath          = Path.Combine(tempFolder, innerFileName);

            if (!File.Exists(filePath))
            {
                // use the directory name to also include folders within the archive
                string directory = Path.GetDirectoryName(filePath);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                string zipFile = searchResult.FileNameReal;
                if (zipFile.Length > 260 && !zipFile.StartsWith(@"\\?\", StringComparison.InvariantCulture))
                {
                    zipFile = @"\\?\" + zipFile;
                }

                using (FileStream input = File.Open(zipFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    ExtractToTempFile(input, filePath, searchResult.FileNameReal, innerFileName, intermediateFiles);
                }
            }

            return(filePath);
        }
Exemple #4
0
        public string ExtractToTempFile(GrepSearchResult searchResult)
        {
            string tempFolder    = Path.Combine(Utils.GetTempFolder(), "dnGREP-Archive", Utils.GetHash(searchResult.FileNameReal));
            string innerFileName = searchResult.FileNameDisplayed.Substring(searchResult.FileNameReal.Length).TrimStart(Path.DirectorySeparatorChar);
            string filePath      = Path.Combine(tempFolder, innerFileName);

            if (!File.Exists(filePath))
            {
                // use the directory name to also include folders within the archive
                string directory = Path.GetDirectoryName(filePath);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                string zipFile = searchResult.FileNameReal;
                if (zipFile.Length > 260 && !zipFile.StartsWith(@"\\?\"))
                {
                    zipFile = @"\\?\" + zipFile;
                }

                using (SevenZipExtractor extractor = new SevenZipExtractor(zipFile))
                {
                    if (extractor.ArchiveFileData.Where(r => r.FileName == innerFileName && !r.IsDirectory).Any())
                    {
                        using (FileStream stream = File.Open(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
                        {
                            try
                            {
                                extractor.ExtractFile(innerFileName, stream);
                            }
                            catch (Exception ex)
                            {
                                logger.Log <Exception>(LogLevel.Error, string.Format("Failed extract file {0} from archive '{1}'", innerFileName, searchResult.FileNameReal), ex);
                            }
                        }
                    }
                }
            }

            return(filePath);
        }
        public LuceneIndex(string LIBRARY_INDEX_BASE_PATH)
        {
            this.LIBRARY_INDEX_BASE_PATH = LIBRARY_INDEX_BASE_PATH;

            CheckIndexVersion();

            // Write the version of the index
            Directory.CreateDirectory(LIBRARY_INDEX_BASE_PATH);
            File.WriteAllText(VersionFilename, INDEX_VERSION);

            // Delete any old locks
            if (File.Exists(LuceneWriteLockFilename))
            {
                Logging.Warn("The lucene file lock was still there (bad shutdown perhaps) - so deleting it");
                File.Delete(LuceneWriteLockFilename);
            }

            // Create our common parts
            analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29, new Hashtable());
        }
Exemple #6
0
 private void LoadKnownWebLibraries(string filename, bool only_load_those_libraries_which_are_actually_present)
 {
     Logging.Info("+Loading known Web Libraries");
     try
     {
         if (File.Exists(filename))
         {
             KnownWebLibrariesFile known_web_libraries_file = SerializeFile.ProtoLoad <KnownWebLibrariesFile>(filename);
             if (null != known_web_libraries_file.web_library_details)
             {
                 //...
             }
         }
     }
     catch (Exception ex)
     {
         Logging.Error(ex, "There was a problem loading the known Web Libraries from config file {0}", filename);
     }
     Logging.Info("-Loading known Web Libraries");
 }
Exemple #7
0
        private async Task InstallIncludedFiles()
        {
            Info("Writing inline files");
            await ModList.Directives.OfType <InlineFile>()
            .PMap(Queue, directive =>
            {
                if (directive.To.EndsWith(Consts.MetaFileExtension))
                {
                    return;
                }

                Info($"Writing included file {directive.To}");
                var outPath = Path.Combine(OutputFolder, directive.To);
                if (File.Exists(outPath))
                {
                    File.Delete(outPath);
                }
                File.WriteAllBytes(outPath, LoadBytesFromPath(directive.SourceDataID));
            });
        }
 internal static string FindValidStyleFilename(string style_filename)
 {
     // If this filename no longer exists, check if we can find the same filename in the default directory
     if (File.Exists(style_filename))
     {
         return(style_filename);
     }
     else
     {
         string new_style_filename = Path.GetFullPath(Path.Combine(BASE_STYLE_DIRECTORY, Path.GetFileName(style_filename)));
         if (File.Exists(new_style_filename))
         {
             return(new_style_filename);
         }
         else
         {
             return(null);
         }
     }
 }
Exemple #9
0
 public static void Rotate(string filenameBase)
 {
     if (File.Exists(filenameBase))
     {
         for (int i = 8; i >= 0; i--)
         {
             string fn = filenameBase + "." + i;
             if (File.Exists(fn))
             {
                 string fn2 = filenameBase + "." + (i + 1);
                 if (File.Exists(fn2))
                 {
                     File.Delete(fn2);
                 }
                 File.Move(fn, fn2);
             }
         }
         File.Copy(filenameBase, filenameBase + ".0");
     }
 }
Exemple #10
0
        public List <GrepLine> GetLinesWithContext(int linesBefore, int linesAfter)
        {
            if (searchResults == null)
            {
                if (File.Exists(FileNameReal))
                {
                    EOL = Utils.GetEOL(FileNameReal, Encoding);

                    using (FileStream reader = File.Open(FileNameReal, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                        using (StreamReader streamReader = new StreamReader(reader, Encoding))
                        {
                            searchResults = Utils.GetLinesEx(streamReader, Matches, linesBefore, linesAfter);
                        }
                }
                else
                {
                    searchResults = new List <GrepLine>();
                }
            }
            return(searchResults);
        }
        public void SyncToDisk()
        {
            if (!_disableDiskCache)
            {
                Utils.Status("Syncing VFS Cache");
                lock (this)
                {
                    try
                    {
                        _isSyncing = true;

                        if (File.Exists("vfs_cache.bin_new"))
                        {
                            File.Delete("vfs_cache.bin_new");
                        }

                        using (var fs = File.OpenWrite("vfs_cache.bin_new"))
                            using (var bw = new BinaryWriter(fs))
                            {
                                Utils.Log($"Syncing VFS to Disk: {_files.Count} entries");
                                foreach (var f in _files.Values)
                                {
                                    f.Write(bw);
                                }
                            }

                        if (File.Exists("vfs_cache.bin"))
                        {
                            File.Delete("vfs_cache.bin");
                        }

                        File.Move("vfs_cache.bin_new", "vfs_cache.bin");
                    }
                    finally
                    {
                        _isSyncing = false;
                    }
                }
            }
        }
Exemple #12
0
        public List <GrepLine> GetLinesWithContext(int linesBefore, int linesAfter)
        {
            if (searchResults == null)
            {
                if (File.Exists(FileNameReal))
                {
                    if (Utils.IsArchive(FileNameReal))
                    {
                        searchResults = ArchiveDirectory.GetLinesWithContext(this, linesBefore, linesAfter);
                    }
                    else
                    {
                        EOL = Utils.GetEOL(FileNameReal, Encoding);

                        using (FileStream reader = File.Open(FileNameReal, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                        {
                            if (IsHexFile)
                            {
                                using (BinaryReader readStream = new BinaryReader(reader))
                                {
                                    searchResults = Utils.GetLinesHexFormat(readStream, Matches, linesBefore, linesAfter);
                                }
                            }
                            else
                            {
                                using (StreamReader streamReader = new StreamReader(reader, Encoding))
                                {
                                    searchResults = Utils.GetLinesEx(streamReader, Matches, linesBefore, linesAfter);
                                }
                            }
                        }
                    }
                }
                else
                {
                    searchResults = new List <GrepLine>();
                }
            }
            return(searchResults);
        }
Exemple #13
0
        public void TestDefaultDictionariesMatch()
        {
            string solutionPath = Directory.GetParent(GetDllPath())
                                  .Parent.Parent.Parent.FullName;

            var path1 = Path.Combine(solutionPath, @"dnGREP.WPF\Themes\LightBrushes.xaml");
            var path2 = Path.Combine(solutionPath, @"dnGREP.WPF\Themes\DarkBrushes.xaml");

            Assert.True(File.Exists(path1));
            Assert.True(File.Exists(path2));

            ResourceDictionary dict1 = LoadXaml(path1);
            ResourceDictionary dict2 = LoadXaml(path2);

            Assert.NotNull(dict1);
            Assert.NotNull(dict2);

            Assert.Equal(dict1.Count, dict2.Count);

            foreach (var key in dict1.Keys)
            {
                Assert.True(dict2.Contains(key));

                object value1 = dict1[key];
                object value2 = dict2[key];

                if (value1 is Brush)
                {
                    Assert.True(value2 is Brush);
                }
                else if (value1 is DropShadowEffect)
                {
                    Assert.True(value2 is DropShadowEffect);
                }
                else if (value1 is bool)
                {
                    Assert.True(value2 is bool);
                }
            }
        }
Exemple #14
0
 public static object LoadRedundant(string filename)
 {
     try
     {
         return(Load(filename));
     }
     catch
     {
         // Check if there is a redundant file to fall back on
         string redundant_filename = filename + REDUNDANT;
         if (File.Exists(redundant_filename))
         {
             File.Delete(filename);
             File.Move(redundant_filename, filename);
             return(Load(filename));
         }
         else
         {
             throw;
         }
     }
 }
        public AITagManager(Library library)
        {
            this.library = new TypedWeakReference <Library>(library);

            current_ai_tags_record = new AITags();

            // Attempt to load the existing tags
            try
            {
                if (File.Exists(Filename_Store))
                {
                    Stopwatch clk = Stopwatch.StartNew();
                    Logging.Info("+Loading AutoTags");
                    current_ai_tags_record = SerializeFile.ProtoLoad <AITags>(Filename_Store);
                    Logging.Info("-Loading AutoTags (time spent: {0} ms)", clk.ElapsedMilliseconds);
                }
            }
            catch (Exception ex)
            {
                Logging.Warn(ex, "There was a problem loading existing AutoTags");
            }
        }
        private static void DoDirectCopy(string vmBackupPath, string snapshotPath, int volumePathLength, string vmPath)
        {
            var srcPath = Path.Combine(snapshotPath, vmPath.Substring(volumePathLength));

            if (Directory.Exists(srcPath))
            {
                foreach (var srcChildPath in Directory.GetFileSystemEntries(srcPath))
                {
                    var srcChildPathRel = srcChildPath.Substring(snapshotPath.EndsWith(Path.PathSeparator.ToString(), StringComparison.CurrentCultureIgnoreCase) ? snapshotPath.Length : snapshotPath.Length + 1);
                    var childPath       = Path.Combine(vmPath.Substring(0, volumePathLength), srcChildPathRel);
                    DoDirectCopy(vmBackupPath, snapshotPath, volumePathLength, childPath);
                }
            }
            else if (File.Exists(srcPath))
            {
                var outputName = Path.Combine(vmBackupPath, vmPath.Substring(volumePathLength));
                var s          = File.OpenRead(srcPath);

                var folder = Path.GetDirectoryName(outputName);
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }

                var ns = File.Create(outputName);
                s.CopyTo(ns);
            }
            else
            {
                var lowerPath   = srcPath.ToLowerInvariant();
                var isIgnorable = lowerPath.EndsWith(".avhdx") || lowerPath.EndsWith(".vmrs") ||
                                  lowerPath.EndsWith(".bin") || lowerPath.EndsWith(".vsv");

                if (!isIgnorable)
                {
                    throw new Exception($"Entry \"{srcPath}\" not found in snapshot");
                }
            }
        }
Exemple #17
0
 public override bool Initialize(GrepEngineInitParams param, FileFilter filter)
 {
     base.Initialize(param, filter);
     try
     {
         // Make sure pdftotext.exe exists
         pathToPdfToText = Utils.GetCurrentPath(typeof(GrepEnginePdf)) + "\\pdftotext.exe";
         if (File.Exists(pathToPdfToText))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         logger.Error(ex, "Failed to find pdftotext.exe.");
         return(false);
     }
 }
        private void IgnoredItems_ContextMenuItem_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                foreach (var junk in IgnoredItems.SelectedItems.OfType <string>().ToList())
                {
                    switch ((string)(sender as MenuItem)?.Tag)
                    {
                    case "Explorer":
                        if (File.Exists(junk) || Directory.Exists(junk))
                        {
                            Process.Start(junk);
                        }
                        break;

                    case "Ignore":
                        Definitions.List.IgnoredJunkItems.Remove(junk);
                        break;

                    case "Delete":
                        if (File.Exists(junk))
                        {
                            File.Delete(junk);
                        }
                        else if (Directory.Exists(junk))
                        {
                            Directory.Delete(junk, true);
                        }

                        Definitions.List.IgnoredJunkItems.Remove(junk);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex);
            }
        }
Exemple #19
0
 public static T ProtoLoad <T>(string filename)
 {
     try
     {
         return(ProtoLoad_NotRedundant <T>(filename));
     }
     catch (Exception ex)
     {
         // Check if there is a redundant file to fall back on
         string redundant_filename = filename + REDUNDANT;
         if (File.Exists(redundant_filename))
         {
             File.Delete(filename);
             File.Move(redundant_filename, filename);
             return(ProtoLoad_NotRedundant <T>(filename));
         }
         else
         {
             throw ex;
         }
     }
 }
Exemple #20
0
        /// <summary>
        ///     Remove any orphaned files in the DB.
        /// </summary>
        private void CleanDB()
        {
            Utils.Log("Cleaning VFS cache");
            lock (this)
            {
                _files.Values
                .Where(f =>
                {
                    if (f.IsConcrete)
                    {
                        return(!File.Exists(f.StagedPath));
                    }
                    if (f.Hash == null)
                    {
                        return(true);
                    }
                    while (f.ParentPath != null)
                    {
                        if (Lookup(f.ParentPath) == null)
                        {
                            return(true);
                        }
                        if (f.Hash == null)
                        {
                            return(true);
                        }
                        f = Lookup(f.ParentPath);
                    }

                    return(false);
                })
                .ToList()
                .Do(f =>
                {
                    _files.Remove(f.FullPath);
                });
                SyncToDisk();
            }
        }
        private void LoadFromDisk()
        {
            try
            {
                Utils.Log("Loading VFS Cache");
                if (!File.Exists("vfs_cache.bin"))
                {
                    return;
                }
                _files = new Dictionary <string, VirtualFile>();

                try
                {
                    using (var fs = File.OpenRead("vfs_cache.bin"))
                        using (var br = new BinaryReader(fs))
                        {
                            while (true)
                            {
                                var fr = VirtualFile.Read(br);
                                _files.Add(fr.FullPath, fr);
                            }
                        }
                }
                catch (EndOfStreamException ex)
                {
                }


                CleanDB();
            }
            catch (Exception ex)
            {
                Utils.Log($"Purging cache due to {ex}");
                File.Delete("vfs_cache.bson");
                _isDirty = true;
                _files.Clear();
            }
        }
Exemple #22
0
        private void CheckIndexVersion()
        {
            string version = String.Empty;

            try
            {
                if (File.Exists(VersionFilename))
                {
                    string[] index_version_lines = File.ReadAllLines(VersionFilename);
                    version = index_version_lines[0].Trim();
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, $"There was a problem while trying to check the index version (path: '{LIBRARY_INDEX_BASE_PATH}')");
            }

            if (0 != String.Compare(version, INDEX_VERSION))
            {
                Logging.Warn("This index is out of date (it's version is {0}), so deleting the index.", version);
                DeleteIndex();
            }
        }
 private void Load()
 {
     // Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start();
     lock (tokens_lock)
     {
         // l1_clk.LockPerfTimerStop();
         try
         {
             if (File.Exists(FILENAME))
             {
                 string[] lines = File.ReadAllLines(FILENAME);
                 foreach (var line in lines)
                 {
                     tokens.Add(line);
                 }
             }
         }
         catch (Exception ex)
         {
             Logging.Warn(ex, "There was a problem loading {0}", FILENAME);
         }
     }
 }
Exemple #24
0
        public void VerifyInstalledFile(string mod, string file)
        {
            var src = Path.Combine(MO2Folder, "mods", mod, file);

            Assert.IsTrue(File.Exists(src), src);

            var dest = Path.Combine(InstallFolder, "mods", mod, file);

            Assert.IsTrue(File.Exists(dest), dest);

            var src_data  = File.ReadAllBytes(src);
            var dest_data = File.ReadAllBytes(dest);

            Assert.AreEqual(src_data.Length, dest_data.Length);

            for (int x = 0; x < src_data.Length; x++)
            {
                if (src_data[x] != dest_data[x])
                {
                    Assert.Fail($"Index {x} of {mod}\\{file} are not the same");
                }
            }
        }
Exemple #25
0
        public static void StoreIcon(string extension, string path, string mimeType)
        {
            if (!File.Exists(path))
            {
                try
                {
                    if (!Directory.Exists(Path.GetDirectoryName(path)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(path));
                    }
                    Bitmap image = IconHandler.IconFromExtension(extension, IconSize.Small);

                    System.Drawing.Imaging.Encoder qualityEncoder = System.Drawing.Imaging.Encoder.Quality;
                    long              quality     = 100;
                    EncoderParameter  ratio       = new EncoderParameter(qualityEncoder, quality);
                    EncoderParameters codecParams = new EncoderParameters(1);
                    codecParams.Param[0] = ratio;
                    ImageCodecInfo mimeCodecInfo = null;
                    foreach (ImageCodecInfo codecInfo in ImageCodecInfo.GetImageEncoders())
                    {
                        if (codecInfo.MimeType == mimeType)
                        {
                            mimeCodecInfo = codecInfo;
                            break;
                        }
                    }
                    if (mimeCodecInfo != null)
                    {
                        image.Save(path, mimeCodecInfo, codecParams); // Save to JPG
                    }
                }
                catch (Exception ex)
                {
                    logger.Log <Exception>(LogLevel.Error, "Failed to create icon", ex);
                }
            }
        }
Exemple #26
0
        private static KeyValue LoadFromFile(string path, bool asBinary)
        {
            if (!File.Exists(path))
            {
                return(null);
            }

            try
            {
                using (var input = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    var kv = new KeyValue();

                    if (asBinary)
                    {
                        if (!kv.TryReadAsBinary(input))
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        if (!kv.ReadAsText(input))
                        {
                            return(null);
                        }
                    }

                    return(kv);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public static LocaleTable Load(string filename)
        {
            try
            {
                if (File.Exists(filename))
                {
                    LocaleTable locale_table = new LocaleTable();

                    string[] lines = File.ReadAllLines(filename);
                    foreach (string line in lines)
                    {
                        string[] parts = line.Split(LINE_SPLITTER_ARRAY, 2);
                        if (2 == parts.Length)
                        {
                            parts[1] = parts[1].Replace("\\n", Environment.NewLine);
                            locale_table[parts[0]] = String.Format(parts[1]);
                        }
                        else
                        {
                            if (!String.IsNullOrWhiteSpace(line))
                            {
                                Logging.Warn("Ignoring locale line: " + line);
                            }
                        }
                    }

                    return(locale_table);
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "Error loading locale file " + filename);
            }

            return(null);
        }
Exemple #28
0
 public static void Load()
 {
     try
     {
         BookmarkEntity bookmarkLib;
         XmlSerializer  serializer = new XmlSerializer(typeof(BookmarkEntity));
         if (!File.Exists(Utils.GetDataFolderPath() + "\\bookmarks.xml"))
         {
             bookmarks = new BookmarkEntity();
         }
         else
         {
             using (TextReader reader = new StreamReader(Utils.GetDataFolderPath() + "\\bookmarks.xml"))
             {
                 bookmarkLib = (BookmarkEntity)serializer.Deserialize(reader);
                 bookmarks   = bookmarkLib;
             }
         }
     }
     catch
     {
         bookmarks = new BookmarkEntity();
     }
 }
Exemple #29
0
        private static void AddPathToCompressionList(IDictionary <string, Stream> files,
                                                     ICollection <Stream> streams, string snapshotPath, int volumePathLength, string vmPath)
        {
            var srcPath = Path.Combine(snapshotPath, vmPath.Substring(volumePathLength));

            if (Directory.Exists(srcPath))
            {
                foreach (var srcChildPath in Directory.GetFileSystemEntries(srcPath))
                {
                    var srcChildPathRel =
                        srcChildPath.Substring(snapshotPath.EndsWith(Path.PathSeparator.ToString(),
                                                                     StringComparison.CurrentCultureIgnoreCase)
                            ? snapshotPath.Length
                            : snapshotPath.Length + 1);
                    var childPath = Path.Combine(vmPath.Substring(0, volumePathLength), srcChildPathRel);
                    AddPathToCompressionList(files, streams, snapshotPath, volumePathLength, childPath);
                }
            }
            else if (File.Exists(srcPath))
            {
                var s = File.OpenRead(srcPath);
                files.Add(vmPath.Substring(volumePathLength), s);
                streams.Add(s);
            }
            else
            {
                var lowerPath   = srcPath.ToLowerInvariant();
                var isIgnorable = lowerPath.EndsWith(".avhdx") || lowerPath.EndsWith(".vmrs") ||
                                  lowerPath.EndsWith(".bin") || lowerPath.EndsWith(".vsv");

                if (!isIgnorable)
                {
                    throw new Exception($"Entry \"{srcPath}\" not found in snapshot");
                }
            }
        }
Exemple #30
0
 public static void Load()
 {
     try
     {
         BookmarkEntity bookmarkLib;
         XmlSerializer  serializer = new XmlSerializer(typeof(BookmarkEntity));
         if (!File.Exists(BookmarksFile))
         {
             bookmarks = new BookmarkEntity();
         }
         else
         {
             using (TextReader reader = new StreamReader(BookmarksFile))
             {
                 bookmarkLib = (BookmarkEntity)serializer.Deserialize(reader);
                 bookmarks   = bookmarkLib;
             }
         }
     }
     catch
     {
         bookmarks = new BookmarkEntity();
     }
 }