예제 #1
0
        /// <summary>
        /// Replace any keys within a file from a dictionary
        /// </summary>
        /// <param name="filePath">path of file to replace keys in</param>
        /// <param name="keyVars">dictionary of words to replace within files</param>
        public static bool UpdateFileWithKeys(string filePath, Dictionary <string, string> keyVars)
        {
            string textInfo = SafeFileManagement.GetFileContents(filePath);

            if (textInfo == null)
            {
                return(false);
            }
            foreach (string key in keyVars.Keys)
            {
                textInfo = textInfo.Replace(key, keyVars[key]);
            }
            return(SafeFileManagement.SetFileContents(filePath, textInfo));
        }
예제 #2
0
        /// <summary>
        /// Get all data from beatsaber map zip file
        /// </summary>
        /// <param name="fileToUnzip">path to beat saber map zip</param>
        /// <param name="pathToUnzip">path to unzip map data</param>
        /// <param name="cancellationToken">token to cancel action</param>
        /// <returns></returns>
        public static async Task <BeatSaberMap> GetDataFromMapZip(string fileToUnzip, string pathToUnzip, CancellationToken cancellationToken)
        {
            string tempUnZipPath = Path.Combine(pathToUnzip, "MapLoader", SafeFileManagement.GetFolderName(fileToUnzip));

            if (Directory.Exists(tempUnZipPath))
            {
                SafeFileManagement.DeleteDirectory(tempUnZipPath);
            }
            Directory.CreateDirectory(tempUnZipPath);
            await Archive.DecompressAsync(fileToUnzip, tempUnZipPath, cancellationToken);

            cancellationToken.ThrowIfCancellationRequested();
            return(await Task.Run(() =>
            {
                string infoPath = Path.Combine(tempUnZipPath, "info.dat");
                Info info = JsonUtility.FromJson <Info>(SafeFileManagement.GetFileContents(infoPath));
                if (info == null)
                {
                    return null;
                }
                info = ConvertSoundFile(tempUnZipPath, info);
                if (info == null)
                {
                    return null;
                }
                info = ConvertImageFiles(tempUnZipPath, info);
                if (info == null)
                {
                    return null;
                }

                cancellationToken.ThrowIfCancellationRequested();

                Dictionary <string, MapDataInfo> mapDataInfos = new Dictionary <string, MapDataInfo>();
                foreach (var beatMapSets in info.DifficultyBeatmapSets)
                {
                    foreach (var beatMap in beatMapSets.DifficultyBeatmaps)
                    {
                        string mapPath = Path.Combine(tempUnZipPath, beatMap.BeatmapFilename);
                        MapData mapData = JsonUtility.FromJson <MapData>(SafeFileManagement.GetFileContents(mapPath));
                        mapDataInfos.Add(beatMap.BeatmapFilename, new MapDataInfo(beatMap, mapData));
                    }
                }
                return new BeatSaberMap(info, mapDataInfos, tempUnZipPath);
            }));
        }