Пример #1
0
        public static void DeployAndResetConfigs(SpringPaths paths, PackageDownloader.Version ver)
        {
            if (ver != null)
            {
                var  oldVers  = LoadFromDisk(paths) ?? new ConfigVersions();
                var  newVers  = LoadFromChobby(ver, paths);
                bool hasError = false;

                if (newVers != null)
                {
                    foreach (
                        var versionEntry in newVers.Versions.Where(x => string.IsNullOrEmpty(x.Platform) || x.Platform == paths.Platform.ToString()))
                    {
                        try
                        {
                            var target = Path.Combine(paths.WritableDirectory, versionEntry.TargetPath);

                            if (
                                !oldVers.Versions.Any(
                                    x =>
                                    x.TargetPath == versionEntry.TargetPath && x.VersionNumber >= versionEntry.VersionNumber &&
                                    x.Platform == versionEntry.Platform) || !File.Exists(target))
                            {
                                var dirName = Path.GetDirectoryName(target);
                                if (!Directory.Exists(dirName))
                                {
                                    Directory.CreateDirectory(dirName);
                                }

                                var content = ver.ReadFile(paths, versionEntry.SourcePath);
                                if (content != null)
                                {
                                    var targetBytes = content.ToArray();

                                    if (!File.Exists(target) || !Hash.ByteArrayEquals(File.ReadAllBytes(target), targetBytes))
                                    {
                                        File.WriteAllBytes(target, targetBytes);
                                    }
                                }
                                else
                                {
                                    File.Delete(target);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            hasError = true;
                            Trace.TraceError("Error processing file deployment {0} : {1}", versionEntry.SourcePath, ex);
                        }
                    }
                }
                if (!hasError)
                {
                    (newVers ?? oldVers).SaveToDisk(paths);
                }
            }
        }
Пример #2
0
        private static ConfigVersions LoadFromChobby(PackageDownloader.Version ver, SpringPaths paths)
        {
            var ms = ver?.ReadFile(paths, FilePathInChobby);

            if (ms != null)
            {
                return(TryDeserialize(Encoding.UTF8.GetString(ms.ToArray())));
            }
            return(null);
        }
Пример #3
0
 private dynamic ExtractEngineFromLua(PackageDownloader.Version ver)
 {
     if (ver != null)
     {
         var     mi            = ver.ReadFile(paths, "modinfo.lua");
         var     lua           = new Lua();
         var     luaEnv        = lua.CreateEnvironment();
         dynamic result        = luaEnv.DoChunk(new StreamReader(mi), "dummy.lua");
         var     engineVersion = result.engine;
         return(engineVersion);
     }
     return(null);
 }