using System; using System.Collections.Generic; using System.IO; using UnityEngine; public class SerializeStorageManager { public SerializeStorageManager() { if (File.Exists(this.ConfigFilePath)) { try { this.config = JsonUtility.FromJson(File.ReadAllText(this.ConfigFilePath)); } catch { } } if (this.config.locationType != SerializeStorageManager.Config.LocationType.Normal) { try { if (!Directory.Exists(this.GetStoreDirectoryPath(this.config.locationType))) { Directory.CreateDirectory(this.GetStoreDirectoryPath(this.config.locationType)); } } catch (Exception exception) { Debug.LogException(exception); } } this.StartSerializeStorageMigrationSequence(); } private string ConfigFilePath { get { return Path.Combine(UTY.gameProjectPath, "serialize_storage_config.cfg"); } } public string StoreDirectoryPath { get { return this.GetStoreDirectoryPath(this.config.locationType); } } public void StartSerializeStorageMigrationSequence() { if (this.config.locationType == SerializeStorageManager.Config.LocationType.Normal) { return; } List list = new List(new string[] { "config.xml", "dance_setting_br.dat", "system.dat", "OvrControllerShortcutConfig.json", "MaidFingerDataList.json", "OvrIK.json" }); List list2 = new List(new string[] { "Thumb", "ScreenShot", "SaveData", "Preset", "PhotoModeData", "MyRoom" }); string storeDirectoryPath = this.GetStoreDirectoryPath(this.config.locationType); string storeDirectoryPath2 = this.GetStoreDirectoryPath(SerializeStorageManager.Config.LocationType.Normal); bool flag = Directory.Exists(Path.Combine(storeDirectoryPath2, "SaveData")); bool flag2 = false; bool flag3 = false; foreach (string path in list) { string path2 = Path.Combine(storeDirectoryPath2, path); string path3 = Path.Combine(storeDirectoryPath, path); if (File.Exists(path2)) { flag3 |= true; } if (Directory.Exists(path3)) { flag2 |= true; } } foreach (string path4 in list2) { string path5 = Path.Combine(storeDirectoryPath2, path4); string path6 = Path.Combine(storeDirectoryPath, path4); if (Directory.Exists(path5)) { flag3 |= true; } if (File.Exists(path6)) { flag2 |= true; } } List> list3 = new List>(); List> list4 = new List>(); if (flag3) { if (flag) { NDebug.MessageBox(string.Empty, "Your save data will be transferred automatically.\nThe new save data location is:\n" + storeDirectoryPath); } if (!flag2) { string text = Path.Combine(this.GetStoreDirectoryPath(SerializeStorageManager.Config.LocationType.Normal), "BackupData_" + DateTime.Now.ToString("yyyyMMddHHmmss")); if (!Directory.Exists(storeDirectoryPath)) { Directory.CreateDirectory(storeDirectoryPath); } if (!Directory.Exists(text)) { Directory.CreateDirectory(text); } foreach (string path7 in list) { string text2 = Path.Combine(storeDirectoryPath2, path7); string text3 = Path.Combine(storeDirectoryPath, path7); if (File.Exists(text2) && !Directory.Exists(text3)) { if (!File.Exists(text3)) { File.Copy(text2, text3); } else { Debug.LogWarning("StartSerializeStorageMigrationSequence\ndestPath:" + text3 + "には既にファイルが存在するためコピーに失敗しました" + text2); } list3.Add(new KeyValuePair(text2, Path.Combine(text, path7))); } } foreach (string path8 in list2) { string text4 = Path.Combine(storeDirectoryPath2, path8); string text5 = Path.Combine(storeDirectoryPath, path8); if (Directory.Exists(text4) && !File.Exists(text5)) { SerializeStorageManager.DirectoryCopy(text4, text5, true); list4.Add(new KeyValuePair(text4, Path.Combine(text, path8))); } } foreach (KeyValuePair keyValuePair in list3) { File.Move(keyValuePair.Key, keyValuePair.Value); } foreach (KeyValuePair keyValuePair2 in list4) { Directory.Move(keyValuePair2.Key, keyValuePair2.Value); } if (flag) { NDebug.MessageBox(string.Empty, "Transfer complete."); } } else if (flag) { NDebug.MessageBox(string.Empty, storeDirectoryPath + "There is already existing data here, so your save data cannot be transferred."); } } } public void SaveConfigFile() { File.WriteAllText(this.ConfigFilePath, JsonUtility.ToJson(this.config)); } private string GetStoreDirectoryPath(SerializeStorageManager.Config.LocationType type) { if (type == SerializeStorageManager.Config.LocationType.Document) { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "KISS\\COM3D2\\"); } return UTY.gameProjectPath + "\\"; } private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs) { DirectoryInfo directoryInfo = new DirectoryInfo(sourceDirName); if (!directoryInfo.Exists) { throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + sourceDirName); } DirectoryInfo[] directories = directoryInfo.GetDirectories(); if (!Directory.Exists(destDirName)) { Directory.CreateDirectory(destDirName); } FileInfo[] files = directoryInfo.GetFiles(); foreach (FileInfo fileInfo in files) { string text = Path.Combine(destDirName, fileInfo.Name); if (!File.Exists(text)) { fileInfo.CopyTo(text, false); } else { Debug.LogWarning("DirectoryCopy\ndestPath:" + text + "には既にファイルが存在するためコピーに失敗しました" + fileInfo.FullName); } } if (copySubDirs) { foreach (DirectoryInfo directoryInfo2 in directories) { string destDirName2 = Path.Combine(destDirName, directoryInfo2.Name); SerializeStorageManager.DirectoryCopy(directoryInfo2.FullName, destDirName2, copySubDirs); } } } private const string ConfigFileName = "serialize_storage_config.cfg"; private SerializeStorageManager.Config config = new SerializeStorageManager.Config(); [Serializable] private class Config : ISerializationCallbackReceiver { public void OnBeforeSerialize() { this.version = 1000; this.locationTypeText = this.locationType.ToString(); } public void OnAfterDeserialize() { this.locationType = SerializeStorageManager.Config.LocationType.Normal; try { if (!string.IsNullOrEmpty(this.locationTypeText)) { this.locationType = (SerializeStorageManager.Config.LocationType)Enum.Parse(typeof(SerializeStorageManager.Config.LocationType), this.locationTypeText, true); } } catch { } } private const int FixVersion = 1000; public int version = 1000; [NonSerialized] public SerializeStorageManager.Config.LocationType locationType; [SerializeField] public string locationTypeText; public enum LocationType { Normal, Document } } }