示例#1
0
 private void DeleteScript(CleanArguments args, LocalScriptFile subscript)
 {
     if (args.Noop)
     {
         Renderer.WriteLine($"Skipping deleting because --noop was specified: {Controller.GetDisplayPath(subscript.FullPath)}", ConsoleColor.Yellow);
     }
     else
     {
         Renderer.WriteLine($"Deleting {Controller.GetDisplayPath(subscript.FullPath)}");
         Controller.Delete(subscript.FullPath);
     }
 }
        public async Task CanFindAndReplaceAScript()
        {
            var folders = new Mock <IFoldersHelper>();

            folders
            .Setup(x => x.ToRelativeToVam(It.IsAny <string>()))
            .Returns((string path) => path.Replace(@"C:\VaM\", ""));
            var scene  = new LocalSceneFile(@"C:\VaM\Saves\My Scene.json");
            var script = new LocalScriptFile(@"C:\VaM\Custom\Scripts\My Script.cs", "SOMEHASH");
            var info   = new LocalPackageInfo
            {
                Files = new[]
                {
                    new InstalledFileInfo
                    {
                        RegistryFile = new RegistryFile
                        {
                            Hash = new RegistryHash
                            {
                                Value = "SOMEHASH"
                            }
                        },
                        FullPath = @"C:\VaM\Custom\Scripts\author\some-package\1.0.0\My Script.cs"
                    }
                }
            };
            var serializer = new Mock <ISceneSerializer>(MockBehavior.Strict);
            var updates    = new List <(string before, string after)> {
                (@"Custom/Scripts/My Script.cs", @"Custom/Scripts/author/some-package/1.0.0/My Script.cs"),
                (@"Saves/Scripts/My Script.cs", @"Custom/Scripts/author/some-package/1.0.0/My Script.cs"),
                (@"My Script.cs", @"Custom/Scripts/author/some-package/1.0.0/My Script.cs")
            };
            var effectiveUpdates = new List <(string before, string after)> {
                (@"Custom/Scripts/My Script.cs", @"Custom/Scripts/author/some-package/1.0.0/My Script.cs")
            };
            var json = new SceneJsonMock(new AtomJsonMock(new PluginJsonMock(@"Custom/Scripts/My Script.cs")));

            serializer
            .Setup(s => s.DeserializeAsync(@"C:\VaM\Saves\My Scene.json"))
            .ReturnsAsync(json);
            serializer
            .Setup(s => s.SerializeAsync(json, @"C:\VaM\Saves\My Scene.json"))
            .Returns(Task.CompletedTask);
            var handler = new UpgradeSceneHandler(serializer.Object, folders.Object);

            var result = await handler.UpgradeSceneAsync(scene, script, info);

            Assert.That(result, Is.EqualTo(1));
            Assert.That(json.Atoms.First().Plugins.First().Path, Is.EqualTo("Custom/Scripts/author/some-package/1.0.0/My Script.cs"));
        }
示例#3
0
 private async Task <LocalScriptFile> LoadScriptAsync(string scriptFile)
 {
     _logger.Verbose($"{scriptFile}: Loading");
     try
     {
         return(new LocalScriptFile(scriptFile, await Hashing.GetHashAsync(_fs, scriptFile).ConfigureAwait(false)));
     }
     catch (Exception exc)
     {
         var script = new LocalScriptFile(scriptFile, await Hashing.GetHashAsync(_fs, scriptFile).ConfigureAwait(false));
         script.AddError(exc.Message, LocalFileErrorLevel.Error);
         _logger.Error($"{scriptFile}: {exc.Message}");
         return(script);
     }
 }
        private Dictionary <string, string> DetermineChanges(LocalScriptFile local, LocalPackageInfo after)
        {
            var changes = new Dictionary <string, string>();

            if (after.Files.Length == 1)
            {
                AddChanges(changes, local.FullPath, after.Files[0].FullPath);
                return(changes);
            }

            var sameFilename = after.Files.FirstOrDefault(f => Path.GetFileName(f.FullPath) == local.FileName);

            if (sameFilename != null)
            {
                AddChanges(changes, local.FullPath, sameFilename.FullPath);
                return(changes);
            }

            throw new NotImplementedException("No automatic strategy implement for this upgrade type");
        }
        public async Task <int> UpgradeSceneAsync(LocalSceneFile scene, LocalScriptFile local, LocalPackageInfo after)
        {
            if (scene is null)
            {
                throw new ArgumentNullException(nameof(scene));
            }
            if (local is null)
            {
                throw new ArgumentNullException(nameof(local));
            }
            if (after is null)
            {
                throw new ArgumentNullException(nameof(after));
            }

            var changes = DetermineChanges(local, after);

            if (changes.Count == 0)
            {
                return(0);
            }

            return(await ApplyChanges(scene, changes).ConfigureAwait(false));
        }
示例#6
0
 internal SavesMapBuilder WithScript(LocalScriptFile script, out LocalScriptFile outScript)
 {
     _scripts.Add(script);
     outScript = script;
     return(this);
 }
示例#7
0
        private async Task <LocalScriptListFile> LoadScriptListAsync(IDictionary <string, LocalScriptFile> scripts, string scriptListFile, bool shouldTryLoadingReferences)
        {
            _logger.Verbose($"{scriptListFile}: Loading");
            var scriptRefs = new List <LocalScriptFile>();

            try
            {
                var scriptRefPaths = await _scriptListSerializer.GetScriptsAsync(scriptListFile);

                foreach (var scriptRefRelativePath in scriptRefPaths)
                {
                    string fullPath = GetReferenceFullPath(scriptListFile, scriptRefRelativePath);
                    if (scripts.TryGetValue(fullPath, out var scriptRef))
                    {
                        scripts.Remove(fullPath);
                        scriptRefs.Add(scriptRef);
                    }
                    else if (_ignoredPaths.Any(p => fullPath.StartsWith(p)))
                    {
                        continue;
                    }
                    else if (shouldTryLoadingReferences)
                    {
                        var script = await LoadScriptAsync(fullPath);

                        scriptRefs.Add(script);
                    }
                    else
                    {
                        var script = new LocalScriptFile(fullPath, null);
                        script.AddError($"Script that does not exist: '{fullPath}'", LocalFileErrorLevel.Error);
                        scriptRefs.Add(script);
                    }
                }

                if (scriptRefs == null || scriptRefs.Count <= 0)
                {
                    return(null);
                }

                var scriptsWithErrors = scriptRefs.Where(s => s.Status > LocalFileErrorLevel.None).ToList();
                var scriptList        = new LocalScriptListFile(scriptListFile, Hashing.GetHash(scriptRefPaths), scriptRefs.ToArray());
                if (scriptsWithErrors.Count == 1)
                {
                    scriptList.AddError($"Script {scriptsWithErrors[0].FullPath} has an issue: {scriptsWithErrors[0].Errors[0].Error}", scriptsWithErrors[0].Status);
                }
                else if (scriptsWithErrors.Count > 1)
                {
                    scriptList.AddError($"{scriptsWithErrors.Count} scripts have issues. First issue: {scriptsWithErrors[0].Errors[0].Error}", scriptsWithErrors[0].Status);
                }

                return(scriptList);
            }
            catch (Exception exc)
            {
                var scriptList = new LocalScriptListFile(scriptListFile, null, scriptRefs.ToArray());
                scriptList.AddError(exc.Message, LocalFileErrorLevel.Error);
                _logger.Error($"{scriptListFile}: {exc.Message}");
                return(scriptList);
            }
        }
 public RegistrySavesMatch(RegistryPackageFileContext remote, LocalScriptFile local)
 {
     Remote = remote;
     Local  = local;
 }