Beispiel #1
0
    public IEnumerator GetPatchFiles(List <string> paths, UnityAction <List <string> > callback)
    {
        var patchFiles = new List <string>();

#if UNITY_WEBGL
        string start = Name + "_";

        int count = paths.Count;
        for (int i = 0; i < count; i++)
        {
            string filepath = paths[i];
            string filename = Path.GetFileName(filepath);

            if (filename.StartsWith(start))
            {
                patchFiles.Add(Paths.Sites + filepath);
                i++;

                for (; i < count; i++)
                {
                    filepath = paths[i];
                    filename = Path.GetFileName(filepath);
                    if (!filename.StartsWith(start))
                    {
                        break;
                    }

                    patchFiles.Add(Paths.Sites + filepath);
                }
                break;
            }
        }
#else
        const int        MaxPatchesPerFrame = 100;
        HashSet <string> hs        = new HashSet <string>();
        string           binFilter = Name + "_*." + Patch.BIN_EXTENSION;
        string           csvFilter = Name + "_*." + Patch.CSV_EXTENSION;
        foreach (var dir in paths)
        {
            hs.Clear();

            var binFiles = Directory.GetFiles(dir, binFilter);
            int count    = binFiles.Length;
            for (int i = 0; i < count; i++)
            {
                var binFile = binFiles[i];
                if (PatchDataIO.CheckBinVersion(binFile))
                {
                    patchFiles.Add(binFile);
                    hs.Add(binFile);
                }
                if (++fileCounter % MaxPatchesPerFrame == 0)
                {
                    yield return(null);
                }
            }

            var csvFiles = Directory.GetFiles(dir, csvFilter);
            count = csvFiles.Length;
            for (int i = 0; i < count; i++)
            {
                var    csvFile = csvFiles[i];
                string binFile = Path.ChangeExtension(csvFile, Patch.BIN_EXTENSION);
                if (hs.Contains(binFile))
                {
                    // Check if CSV is newer than the BIN
                    if (File.GetLastWriteTime(csvFile) >= File.GetLastWriteTime(binFile))
                    {
                        patchFiles[patchFiles.IndexOf(binFile)] = csvFile;
                    }
                }
                else
                {
                    patchFiles.Add(csvFile);
                }
                if (++fileCounter % MaxPatchesPerFrame == 0)
                {
                    yield return(null);
                }
            }
        }
#endif

#if SAFETY_CHECK
        // Check if all patch filenames match exactly (without ignoring case)
        foreach (var patchFile in patchFiles)
        {
            if (!patchFile.Contains(Name))
            {
                Debug.LogWarning("Patch " + patchFile + " has wrong case, should be: " + Name);
            }
        }
#endif

        callback(patchFiles);

#if UNITY_WEBGL
        yield break;
#endif
    }