示例#1
0
        public void TestCreateDir__Url()
        {
            UrlDir dir = UrlBuilder.CreateDir("abc/def");

            Assert.Equal("def", dir.name);

            UrlDir parent = dir.parent;

            Assert.NotNull(parent);
            Assert.Equal("abc", parent.name);
            Assert.Contains(dir, parent.children);

            UrlDir root = parent.parent;

            Assert.NotNull(root);
            Assert.Equal("root", root.name);
            Assert.Contains(parent, root.children);
            Assert.Null(root.parent);

            Assert.Same(root, root.root);
            Assert.Same(root, parent.root);
            Assert.Same(root, dir.root);

            Assert.Contains(dir, root.AllDirectories);
        }
示例#2
0
        public static UrlDir CreateDir(string url, UrlDir parent = null)
        {
            if (parent == null)
            {
                parent = CreateRoot();
            }
            else
            {
                UrlDir existingDir = parent.GetDirectory(url);
                if (existingDir != null)
                {
                    return(existingDir);
                }
            }

            UrlDir current = parent;

            foreach (string name in url.Split('/'))
            {
                UrlDir dir = CreateRoot();
                UrlDir__field__name.SetValue(dir, name);
                UrlDir__field__root.SetValue(dir, current.root);
                UrlDir__field__parent.SetValue(dir, current);

                current.children.Add(dir);
                current = dir;
            }

            return(current);
        }
示例#3
0
        public static UrlDir CreateGameData(UrlDir root = null)
        {
            if (root == null)
            {
                root = CreateRoot();
            }
            else
            {
                UrlDir potentialGameData = root.children.FirstOrDefault(dir => dir.type == UrlDir.DirectoryType.GameData && dir.name == "");
                if (potentialGameData != null)
                {
                    return(potentialGameData);
                }
            }

            UrlDir gameData = CreateRoot();

            UrlDir__field__name.SetValue(gameData, "");
            UrlDir__field__type.SetValue(gameData, UrlDir.DirectoryType.GameData);
            UrlDir__field__root.SetValue(gameData, root);
            UrlDir__field__parent.SetValue(gameData, root);

            root.children.Add(gameData);

            return(gameData);
        }
        public static TextureInfoWrapper DDSToTexture(UrlDir.UrlFile file, TexInfo Texture, bool mipmaps, bool isCompressed, bool hasAlpha)
        {
            TextureConverter.InitImageBuffer();
            FileStream imgStream = new FileStream(Texture.filename, FileMode.Open, FileAccess.Read);
            imgStream.Position = 0;
            imgStream.Read(imageBuffer, 0, MAX_IMAGE_SIZE);
            imgStream.Close();

            TextureFormat format = TextureFormat.DXT1;
            if(hasAlpha && isCompressed)
            {
                format = TextureFormat.DXT5;
            }
            else if(hasAlpha)
            {
                format = TextureFormat.RGBA32;
            }
            else if(!isCompressed)
            {
                format = TextureFormat.RGB24;
            }

            Texture2D newTex = new Texture2D(Texture.width, Texture.height, format, mipmaps);

            newTex.LoadRawTextureData(imageBuffer);
            newTex.Apply(false, Texture.makeNotReadable);
            newTex.name = Texture.name;

            TextureInfoWrapper newTexInfo = new TextureInfoWrapper(file, newTex, Texture.isNormalMap, !Texture.makeNotReadable, isCompressed);
            newTexInfo.name = Texture.name;
            return newTexInfo;
        }
        public PatchExtractorTest()
        {
            root = UrlBuilder.CreateRoot();
            file = UrlBuilder.CreateFile("abc/def.cfg", root);

            progress = Substitute.For <IPatchProgress>();
        }
示例#6
0
        public void TestCreateFile__Url__AlreadyExists()
        {
            UrlDir root = UrlBuilder.CreateRoot();

            UrlDir.UrlFile file1 = UrlBuilder.CreateFile("abc/def.txt", root);
            UrlDir.UrlFile file2 = UrlBuilder.CreateFile("abc/def.txt", root);

            Assert.Same(file1, file2);

            Assert.Equal("def", file1.name);
            Assert.Equal("txt", file1.fileExtension);
            Assert.Equal(UrlDir.FileType.Unknown, file1.fileType);
            Assert.Equal("abc/def", file1.url);

            UrlDir parent1 = file1.parent;

            Assert.NotNull(parent1);
            Assert.Equal("abc", parent1.name);
            Assert.Contains(file1, parent1.files);

            Assert.Same(root, file1.root);
            Assert.Same(root, parent1.root);

            Assert.Contains(file1, root.AllFiles);
        }
示例#7
0
        // Get the model file name for a part by reading the cfg file contents
        UrlDir.UrlFile GetModelFile(Part part)
        {
            AvailablePart availablePart = part.partInfo;

            /*
             * TESTS
             * Debug.Log("AvailPart: " + availablePart.name);
             * Debug.Log("mesh: " + availablePart.partConfig.GetValue("mesh"));
             * Debug.Log("MODEL: " +
             *     (availablePart.partConfig.GetNode("MODEL") != null ?
             *     availablePart.partConfig.GetNode("MODEL").GetValue("model") :
             *     "none"));
             */

            // Check for an entry in either the PART.model property or the PART.MODEL.model value
            string modelName = availablePart.partConfig.GetValue("mesh");

            if (modelName != null)
            {
                // The "url" is on the firmat "Parts/<PartType>/<ConfigFileName>/<PartName>
                // We need to strip away the ConfigFileName and PartName to get the real path
                string[] urlParts = availablePart.partUrl.Split('/');
                string   url      = "";
                for (int i = 0; i < urlParts.Count() - 2; i++)
                {
                    url += urlParts[i] + "/";
                }

                modelName = url + modelName;
            }
            else
            {
                modelName = availablePart.partConfig.GetNode("MODEL").GetValue("model") + ".mu";
            }

            // Calculate the proper URLs for the file
            string   directory = Path.GetDirectoryName(modelName);
            FileInfo file      = new FileInfo("GameData/" + modelName);

            // Generate the root directory
            UrlDir root = UrlBuilder.CreateDir(directory);

            UrlDir.UrlFile modelFile = new UrlDir.UrlFile(root, file);

            // Apperently, if the file is name "model.mu" the reader is supposed to just
            // pick the first file in the folder... =S
            if (!File.Exists("GameData/" + modelName))
            {
                IEnumerable <UrlDir.UrlFile> modelFiles = root.GetFiles(UrlDir.FileType.Model);

                foreach (UrlDir.UrlFile mFile in modelFiles)
                {
                    Debug.Log("modelFiles: " + mFile.name);
                }
            }

            // Create the full path and name of the model file
            return(modelFile);
        }
        public void TestFind__NotFound()
        {
            UrlDir urlDir = UrlBuilder.CreateDir("abc");

            UrlBuilder.CreateDir("def", urlDir);

            Assert.Null(urlDir.Find("def/ghi"));
        }
        public void TestFind__DirectChild()
        {
            UrlDir urlDir = UrlBuilder.CreateDir("abc");

            UrlDir.UrlFile urlFile = UrlBuilder.CreateFile("def.cfg", urlDir);

            Assert.Equal(urlFile, urlDir.Find("def"));
        }
示例#10
0
 void printPathRecursive(UrlDir dir)
 {
     (dir.url + " / " + dir.path + " / " + dir.type + " / " + dir.root.path).Log();
     foreach (var sub in dir.children)
     {
         printPathRecursive(sub);
     }
 }
示例#11
0
        public void TestCreateGameData__SpecifyRoot__GameDataAlreadyExists()
        {
            UrlDir root      = UrlBuilder.CreateRoot();
            UrlDir gameData1 = UrlBuilder.CreateGameData(root);
            UrlDir gameData2 = UrlBuilder.CreateGameData(root);

            Assert.Same(gameData1, gameData2);
        }
示例#12
0
        public void TestCreateRoot()
        {
            UrlDir root = UrlBuilder.CreateRoot();

            Assert.Equal("root", root.name);
            Assert.Null(root.parent);
            Assert.Same(root, root.root);
        }
        public NeedsCheckerTest()
        {
            root     = UrlBuilder.CreateRoot();
            gameData = UrlBuilder.CreateGameData(root);
            file     = UrlBuilder.CreateFile("abc/def.cfg", gameData);

            progress = Substitute.For <IPatchProgress>();
            logger   = Substitute.For <IBasicLogger>();
        }
示例#14
0
 public PatchApplierTest()
 {
     logger       = Substitute.For <IBasicLogger>();
     progress     = Substitute.For <IPatchProgress>();
     databaseRoot = UrlBuilder.CreateRoot();
     file         = UrlBuilder.CreateFile("abc/def.cfg", databaseRoot);
     patchList    = new PatchList(modList);
     patchApplier = new PatchApplier(patchList, databaseRoot, progress, logger);
 }
示例#15
0
        public PatchApplier(PatchList patchList, UrlDir databaseRoot, IPatchProgress progress, IBasicLogger logger)
        {
            this.patchList    = patchList;
            this.databaseRoot = databaseRoot;
            this.progress     = progress;
            this.logger       = logger;

            allConfigFiles = databaseRoot.AllConfigFiles.ToArray();
        }
        public void TestFind__Extension__NotFound()
        {
            UrlDir urlDir = UrlBuilder.CreateDir("abc");

            UrlBuilder.CreateFile("def/ghi.yyy", urlDir);
            UrlBuilder.CreateFile("def/ghi.zzz", urlDir);

            Assert.Null(urlDir.Find("def/ghi.cfg"));
        }
示例#17
0
        public NeedsCheckerTest()
        {
            gameData = UrlBuilder.CreateGameData();

            progress = Substitute.For <IPatchProgress>();
            logger   = Substitute.For <IBasicLogger>();

            needsChecker = new NeedsChecker(new[] { "mod1", "mod2", "mod/2" }, gameData, progress, logger);
        }
        public void TestFind__Extension()
        {
            UrlDir urlDir = UrlBuilder.CreateDir("abc");

            UrlBuilder.CreateFile("def/ghi.yyy", urlDir);
            UrlDir.UrlFile urlFile = UrlBuilder.CreateFile("def/ghi.cfg", urlDir);
            UrlBuilder.CreateFile("def/ghi.zzz", urlDir);

            Assert.Equal(urlFile, urlDir.Find("def/ghi.cfg"));
        }
示例#19
0
        public static UrlDir.UrlConfig CreateConfig(string url, ConfigNode node, UrlDir parent = null)
        {
            if (Path.GetExtension(url) != ".cfg")
            {
                url += ".cfg";
            }

            UrlDir.UrlFile file = CreateFile(url, parent);

            return(CreateConfig(node, file));
        }
示例#20
0
        public void TestCreateGameData__SpecifyRoot()
        {
            UrlDir root     = UrlBuilder.CreateRoot();
            UrlDir gameData = UrlBuilder.CreateGameData(root);

            Assert.Equal("", gameData.name);
            Assert.Equal("", gameData.url);
            Assert.Equal(UrlDir.DirectoryType.GameData, gameData.type);
            Assert.Same(root, gameData.parent);
            Assert.Contains(gameData, root.children);
        }
示例#21
0
        public NavBallTexture([NotNull] UrlDir skinDirectory)
        {
            if (skinDirectory == null)
            {
                throw new ArgumentNullException("skinDirectory");
            }

            _stockTexture   = new Lazy <Texture>(GetStockTexture);
            _flightMaterial = new Lazy <Material>(GetFlightNavBallMaterial);

            _skinDirectory = skinDirectory;
        }
示例#22
0
        public void Start()
        {
            PartResourceLibrary.Instance.LoadDefinitions();

            ConfigNode paramsNode = null;

            foreach (ConfigNode n in GameDatabase.Instance.GetConfigNodes("LRTRCONFIG"))
            {
                paramsNode = n;
            }

            if (paramsNode == null)
            {
                Debug.LogError("[LRTRCONFIG] Could not find LRTRCONFIG node.");
                return;
            }

            // get configs from DB
            UrlDir.UrlFile root = null;
            foreach (UrlDir.UrlConfig url in GameDatabase.Instance.root.AllConfigs)
            {
                root = url.parent; break;
            }

            // get mod directories
            UrlDir gameData = GameDatabase.Instance.root.children.First(dir => dir.type == UrlDir.DirectoryType.GameData);

            foreach (ConfigNode feature in paramsNode.GetNodes())
            {
                bool enableFeature = false;

                if (feature.GetValue("enabled") != null)
                {
                    enableFeature = feature.GetValue("enabled").ToLower() == "true";
                }
                string[] disabledBy = feature.GetValues("disabledBy");
                foreach (string modName in disabledBy)
                {
                    foreach (UrlDir subDir in gameData.children)
                    {
                        if (String.Compare(modName, subDir.name, true) == 0)
                        {
                            enableFeature = false;
                            Debug.Log("[LRTRCONFIG] " + feature.name + " disabled by " + modName);
                        }
                    }
                }
                if (enableFeature)
                {
                    Inject(root, "LRTR", feature.name);
                }
            }
        }
        public PatchExtractorTest()
        {
            root = UrlBuilder.CreateRoot();
            file = UrlBuilder.CreateFile("abc/def.cfg", root);

            progress          = Substitute.For <IPatchProgress>();
            logger            = Substitute.For <IBasicLogger>();
            needsChecker      = Substitute.For <INeedsChecker>();
            tagListParser     = Substitute.For <ITagListParser>();
            protoPatchBuilder = Substitute.For <IProtoPatchBuilder>();
            patchCompiler     = Substitute.For <IPatchCompiler>();
            patchExtractor    = new PatchExtractor(progress, logger, needsChecker, tagListParser, protoPatchBuilder, patchCompiler);
        }
示例#24
0
        public static UrlDir.UrlFile CreateFile(string path, UrlDir parent = null)
        {
            int    sepIndex = path.LastIndexOf('/');
            string name     = path;

            if (sepIndex != -1)
            {
                parent = CreateDir(path.Substring(0, sepIndex), parent);
                name   = path.Substring(sepIndex + 1);
            }
            else if (parent == null)
            {
                parent = CreateRoot();
            }

            string nameWithoutExtension = Path.GetFileNameWithoutExtension(name);
            string extension            = Path.GetExtension(name);

            if (!string.IsNullOrEmpty(extension))
            {
                extension = extension.Substring(1);
            }

            UrlDir.UrlFile existingFile = parent.files.FirstOrDefault(f => f.name == nameWithoutExtension && f.fileExtension == extension);
            if (existingFile != null)
            {
                return(existingFile);
            }

            bool   cfg     = false;
            string newName = name;

            if (extension == "cfg")
            {
                cfg     = true;
                newName = name + ".not_cfg";
            }

            UrlDir.UrlFile file = new UrlDir.UrlFile(parent, new FileInfo(newName));

            if (cfg)
            {
                UrlFile__field__name.SetValue(file, nameWithoutExtension);
                UrlFile__field__fileExtension.SetValue(file, "cfg");
                UrlFile__field__fileType.SetValue(file, UrlDir.FileType.Config);
            }

            parent.files.Add(file);

            return(file);
        }
示例#25
0
        private IEnumerable <string> CheckUnexpectedUrls()
        {
            UrlDir gameData = GameDatabase.Instance.root.children.First(dir => dir.type == UrlDir.DirectoryType.GameData);

            foreach (string unexpectedUrl in UNEXPECTED_URLS)
            {
                if (!(gameData.GetDirectory(unexpectedUrl) is UrlDir unexpectedDir))
                {
                    continue;
                }
                Debug.LogError("[ReStock] Found unexpected directory " + unexpectedDir.path);
                yield return($"Found unexpected directory, likely left over from an older version of KSP:\n" + unexpectedDir.path);
            }
        }
示例#26
0
            static void WriteDirectoryRecursive(UrlDir currentDir, string dirPath)
            {
                if (currentDir.files.Count > 0)
                {
                    Directory.CreateDirectory(dirPath);
                }

                foreach (UrlDir.UrlFile urlFile in currentDir.files)
                {
                    if (urlFile.fileType != UrlDir.FileType.Config)
                    {
                        continue;
                    }

                    Log("Exporting " + urlFile.GetUrlWithExtension());
                    string filePath = Path.Combine(dirPath, urlFile.GetNameWithExtension());

                    bool first = true;

                    using FileStream stream   = new FileStream(filePath, FileMode.Create);
                    using StreamWriter writer = new StreamWriter(stream);
                    foreach (UrlDir.UrlConfig urlConfig in urlFile.configs)
                    {
                        try
                        {
                            if (first)
                            {
                                first = false;
                            }
                            else
                            {
                                writer.Write("\n");
                            }

                            ConfigNode copy = urlConfig.config.DeepCopy();
                            copy.EscapeValuesRecursive();
                            writer.Write(copy.ToString());
                        }
                        catch (Exception e)
                        {
                            Log("Exception while trying to write the file " + filePath + "\n" + e);
                        }
                    }
                }

                foreach (UrlDir urlDir in currentDir.children)
                {
                    WriteDirectoryRecursive(urlDir, Path.Combine(dirPath, urlDir.name));
                }
            }
示例#27
0
        public static UrlDir.UrlFile Find(this UrlDir urlDir, string url)
        {
            if (urlDir == null)
            {
                throw new ArgumentNullException(nameof(urlDir));
            }
            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }
            string[] splits = url.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            UrlDir currentDir = urlDir;

            for (int i = 0; i < splits.Length - 1; i++)
            {
                currentDir = currentDir.children.FirstOrDefault(subDir => subDir.name == splits[i]);
                if (currentDir == null)
                {
                    return(null);
                }
            }

            string fileName      = splits[splits.Length - 1];
            string fileExtension = null;

            int idx = fileName.LastIndexOf('.');

            if (idx > -1)
            {
                fileExtension = fileName.Substring(idx + 1);
                fileName      = fileName.Substring(0, idx);
            }

            foreach (UrlDir.UrlFile file in currentDir.files)
            {
                if (file.name != fileName)
                {
                    continue;
                }
                if (fileExtension != null && fileExtension != file.fileExtension)
                {
                    continue;
                }
                return(file);
            }

            return(null);
        }
示例#28
0
        public void TestCreateGameData()
        {
            UrlDir gameData = UrlBuilder.CreateGameData();

            Assert.Equal("", gameData.name);
            Assert.Equal("", gameData.url);
            Assert.Equal(UrlDir.DirectoryType.GameData, gameData.type);
            UrlDir root = Assert.IsType <UrlDir>(gameData.root);

            Assert.Same(root, gameData.parent);
            Assert.Equal("root", root.name);
            Assert.Null(root.parent);
            Assert.Same(root, root.root);
            Assert.Contains(gameData, root.children);
        }
示例#29
0
        public void TestCreateConfig__Url__FileAlreadyExists()
        {
            UrlDir root = UrlBuilder.CreateRoot();

            ConfigNode node1 = new TestConfigNode("SOME_NODE")
            {
                { "name", "blah" },
                { "foo", "bar" },
            };

            ConfigNode node2 = new TestConfigNode("SOME_OTHER_NODE")
            {
                { "name", "bleh" },
                { "jazz", "hands" },
            };

            UrlDir.UrlConfig config1 = UrlBuilder.CreateConfig("abc/def", node1, root);
            UrlDir.UrlConfig config2 = UrlBuilder.CreateConfig("abc/def", node2, root);

            UrlDir.UrlFile file = config1.parent;
            Assert.NotNull(file);

            Assert.Same(file, config2.parent);

            Assert.Equal("def", file.name);
            Assert.Equal("cfg", file.fileExtension);
            Assert.Equal(UrlDir.FileType.Config, file.fileType);
            Assert.Contains(config1, file.configs);
            Assert.Contains(config2, file.configs);

            UrlDir parent = file.parent;

            Assert.NotNull(parent);
            Assert.Equal("abc", parent.name);
            Assert.Contains(file, parent.files);

            Assert.Contains(parent, root.children);

            Assert.Same(root, file.root);
            Assert.Same(root, parent.root);
            Assert.Same(root, root.root);

            Assert.Contains(config1, root.AllConfigs);
            Assert.Contains(config1, root.GetConfigs("SOME_NODE"));

            Assert.Contains(config2, root.AllConfigs);
            Assert.Contains(config2, root.GetConfigs("SOME_OTHER_NODE"));
        }
示例#30
0
        public void TestCreateFile()
        {
            UrlDir.UrlFile file = UrlBuilder.CreateFile("someFile.txt");

            Assert.Equal("someFile", file.name);
            Assert.Equal("txt", file.fileExtension);
            Assert.Equal(UrlDir.FileType.Unknown, file.fileType);

            UrlDir root = file.parent;

            Assert.NotNull(root);
            Assert.Equal("root", root.name);
            Assert.Null(root.parent);
            Assert.Contains(file, root.files);
            Assert.Same(root, file.root);
        }
示例#31
0
        public void TestCreateDir()
        {
            UrlDir dir = UrlBuilder.CreateDir("abc");

            Assert.Equal("abc", dir.name);

            UrlDir root = dir.parent;

            Assert.NotNull(root);
            Assert.Equal("root", root.name);
            Assert.Null(root.parent);
            Assert.Contains(dir, root.children);

            Assert.Same(root, dir.root);
            Assert.Same(root, root.root);
        }
        private bool CheckFilesChange(UrlDir.UrlFile[] files, ConfigNode shaConfigNode)
        {
            bool noChange = true;
            StringBuilder changes = new StringBuilder();
            
            for (int i = 0; i < files.Length; i++)
            {
                ConfigNode fileNode = getFileNode(shaConfigNode, files[i].url);
                string fileSha = fileNode != null ? fileNode.GetValue("SHA") : null;

                if (fileNode == null)
                    continue;

                if (fileSha == null || filesSha[files[i].url] != fileSha)
                {
                    changes.Append("Changed : " + fileNode.GetValue("filename") + ".cfg\n");
                    noChange = false;
                }
            }
            for (int i = 0; i < files.Length; i++)
            {
                ConfigNode fileNode = getFileNode(shaConfigNode, files[i].url);

                if (fileNode == null)
                {
                    changes.Append("Added   : " + files[i].url + ".cfg\n");
                    noChange = false;
                }
                shaConfigNode.RemoveNode(fileNode);
            }
            foreach (ConfigNode fileNode in shaConfigNode.GetNodes())
            {
                changes.Append("Deleted : " + fileNode.GetValue("filename") + ".cfg\n");
                noChange = false;
            }
            if (!noChange)
                log("Changes :\n" + changes.ToString());
            return noChange;
        }
 public ConfigWrapper(UrlDir.UrlConfig uc)
 {
     name = uc.parent.url;
     node = uc.config;
 }
 public TextureInfoWrapper(UrlDir.UrlFile file, UnityEngine.Texture2D newTex, bool nrmMap, bool readable, bool compress)
     : base(file, newTex, nrmMap, readable, compress)
 {
 }
 public TexInfo(UrlDir.UrlFile file)
 {
     this.file = file;
     this.name = file.url;
     this.isNormalMap = DatabaseLoaderTexture_ATM.IsNormal(name);
     this.width = 1;
     this.height = 1;
     loadOriginalFirst = false;
     needsResize = false;
     makeNotReadable = true;
 }
 private string PrettyConfig(UrlDir.UrlConfig config)
 {
     StringBuilder sb = new StringBuilder();
     sb.AppendFormat("{0}[{1}]\n", config.type ?? "NULL", config.name ?? "NULL");
     try
     {
         if (config.config != null)
         {
             PrettyConfig(config.config, ref sb, "  ");
         }
         else
         {
             sb.Append("NULL\n");
         }
         sb.Append("\n");
     }
     catch (Exception e)
     {
         log("PrettyConfig Exception " + e);
     }
     return sb.ToString();
 }
 public void addErrorFiles(UrlDir.UrlFile file, int n = 1)
 {
     string key = file.url + "." + file.fileExtension;
     if (key[0] == '/')
         key = key.Substring(1);
     if (!errorFiles.ContainsKey(key))
         errorFiles.Add(key, n);
     else
         errorFiles[key] = errorFiles[key] + n;
 }