Beispiel #1
0
    private bool LoadSubFiles(string fileName, string basePath, Dictionary <string, Queue <string> > canonicalPathCache)
    {
        string cacheFileName = fileName.Replace(@"\", @"/").ToLower();

        LdFileParser.FileLines fileLines;
        HashSet <string>       localSubFileNames = new HashSet <string>();

        if (fileCache.TryGetValue(cacheFileName, out fileLines))
        {
            if (fileLines.LoadCompleted)
            {
                return(true);
            }

            LdSubFileNameLoader.ExtractSubFileNames(fileLines.cache.ToArray(), ref localSubFileNames);
            fileCache[cacheFileName].LoadCompleted = true;
        }
        else
        {
            Queue <string> pathQueue;
            if (!canonicalPathCache.TryGetValue(cacheFileName, out pathQueue) || pathQueue.Count == 0)
            {
                Debug.Log(string.Format("Parts path cache has no {0}", cacheFileName));
                return(false);
            }

            var    val        = pathQueue.First();
            var    filePath   = Path.Combine(basePath, val);
            string readString = null;

            if (!LoadFile(filePath, ref readString))
            {
                return(false);
            }

            if (readString.Length == 0)
            {
                return(false);
            }

            string[] readText = readString.Split(
                Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            LdSubFileNameLoader.ExtractSubFileNames(readText, ref localSubFileNames);
            fileCache.Add(cacheFileName, new LdFileParser.FileLines(val, readText));
        }

        if (localSubFileNames.Count > 0)
        {
            subFileNames.UnionWith(localSubFileNames);
        }

        return(true);
    }
Beispiel #2
0
    void LoadCacheFiles(string fileName)
    {
        string cacheFileName = fileName.Replace(@"\", @"/").ToLower();

        LdFileParser.FileLines fileLines;
        HashSet <string>       localSubFileNames = new HashSet <string>();

        if (fileCache.TryGetValue(cacheFileName, out fileLines))
        {
            if (fileLines.LoadCompleted)
            {
                return;
            }

            LdSubFileNameLoader.ExtractSubFileNames(fileLines.cache.ToArray(), ref localSubFileNames);
            fileCache[cacheFileName].LoadCompleted = true;
        }
        else
        {
            Queue <string> pathQueue;
            if (!partsPathCache.TryGetValue(cacheFileName, out pathQueue) || pathQueue.Count == 0)
            {
                Debug.Log(string.Format("Parts path has no {0}", cacheFileName));
                return;
            }

            string val      = pathQueue.Peek();
            string filePath = Path.Combine(GetBasePartImportPath(), val);

            FileLoader fileLoader = new FileLoader();
            if (!fileLoader.LoadFile(filePath))
            {
                return;
            }

            string[] readText;
            if (!fileLoader.GetSplitLines(out readText))
            {
                return;
            }

            LdSubFileNameLoader.ExtractSubFileNames(readText, ref localSubFileNames);
            fileCache.Add(cacheFileName, new LdFileParser.FileLines(val, readText));
        }
        if (localSubFileNames.Count > 0)
        {
            subFileNames.UnionWith(localSubFileNames);
        }
    }