Esempio n. 1
0
        private async Task ComputeHashAsync(FreeFile matchingFreeFile)
        {
            var bytes = await _fs.File.ReadAllBytesAsync(matchingFreeFile.Path);

            matchingFreeFile.Size = bytes.Length;
            matchingFreeFile.Hash = _hashingAlgo.GetHash(bytes);
        }
Esempio n. 2
0
 private static FreeFilePackageMatch GivenPackageMatch(string filename, FreeFile scriptFile, int additionalFiles = 0)
 {
     return(new FreeFilePackageMatch(
                new VarPackage(
                    VarPackageName.TryGet(filename, out var name) ? name : null,
                    "absolute-path",
                    Enumerable
                    .Range(0, 1 + additionalFiles)
                    .Select(i => new VarPackageFile($@"Custom\Scripts\{i}.cs", $"hash:{i}"))
                    .ToList()),
                new VarPackageFile(@"Custom\Scripts\MyScript.cs", "hash"),
                new[] { scriptFile }));
 }
Esempio n. 3
0
        private async Task ScanSceneAsync(string vam, FreeFile potentialScene, int potentialScenesCount, ConcurrentDictionary <string, FreeFile> filesIndex, ProgressReporter <ProgressInfo> reporter)
        {
            reporter.Report(new ProgressInfo(Interlocked.Increment(ref _scanned), potentialScenesCount, potentialScene.LocalPath));

            var potentialSceneJson = await _fs.File.ReadAllTextAsync(potentialScene.Path);

            var potentialSceneReferences = _findFilesFastRegex.Matches(potentialSceneJson).Where(m => m.Success).Select(m => m.Groups["path"]);
            var sceneFolder = _fs.Path.GetDirectoryName(potentialScene.Path);
            var references  = new List <SceneReference>();
            var missing     = new HashSet <string>();

            foreach (var reference in potentialSceneReferences)
            {
                if (!reference.Success)
                {
                    continue;
                }
                var refPath = reference.Value;
                if (refPath.Contains(":"))
                {
                    continue;
                }
                refPath = refPath.NormalizePathSeparators();
                refPath = MigrateLegacyPaths(refPath);
                if (filesIndex.TryGetValue(_fs.Path.GetFullPath(_fs.Path.Combine(sceneFolder, refPath)), out var f1))
                {
                    references.Add(new SceneReference(f1, reference.Index, reference.Length));
                }
                else if (filesIndex.TryGetValue(_fs.Path.GetFullPath(_fs.Path.Combine(vam, refPath)), out var f2))
                {
                    references.Add(new SceneReference(f2, reference.Index, reference.Length));
                }
                else
                {
                    missing.Add(refPath);
                }
            }
            var item = new JsonFile(potentialScene, references, missing.ToList());

            if (references.Count > 0)
            {
                _scenes.Add(item);
            }
        }
Esempio n. 4
0
        public async Task CanReplacePaths()
        {
            _fs.AddFile(@$ "{_vamPath}\Saves\scene\MyScene.json", new MockFileData(@"{""id"":""Custom\Scripts\Script1.cs"", ""path"":""Script1.cs""}"));
            var op         = new UpdateJsonFileReferencesOperation(_consoleOutput.Object, _fs, Mock.Of <ILogger>());
            var scriptFile = new FreeFile("", @"Custom\Scripts\MyScript.cs");
            var scenes     = GivenFiles(@"Saves\scene\MyScene.json").Select(f => new JsonFile(f, new List <SceneReference>
            {
                new SceneReference(scriptFile, 7, 25),
                new SceneReference(scriptFile, 43, 10),
            },
                                                                                              new List <string>()
                                                                                              )).ToList();
            var matches = new List <FreeFilePackageMatch>
            {
                GivenPackageMatch("Author.Name.1.var", scriptFile)
            };

            await op.ExecuteAsync(scenes, matches, ExecutionOptions.Default);

            Assert.That(_fs.GetFile($@"{_vamPath}\Saves\scene\MyScene.json").TextContents, Is.EqualTo(@"{""id"":""Author.Name.1:/Custom/Scripts/MyScript.cs"", ""path"":""Author.Name.1:/Custom/Scripts/MyScript.cs""}"));
        }
Esempio n. 5
0
 public SceneReference(FreeFile file, int index, int length)
 {
     File   = file;
     Index  = index;
     Length = length;
 }