123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- 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<SerializeStorageManager.Config>(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<string> list = new List<string>(new string[]
- {
- "config.xml",
- "dance_setting_br.dat",
- "system.dat",
- "OvrControllerShortcutConfig.json",
- "MaidFingerDataList.json",
- "OvrIK.json"
- });
- List<string> list2 = new List<string>(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<KeyValuePair<string, string>> list3 = new List<KeyValuePair<string, string>>();
- List<KeyValuePair<string, string>> list4 = new List<KeyValuePair<string, string>>();
- 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<string, string>(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<string, string>(text4, Path.Combine(text, path8)));
- }
- }
- foreach (KeyValuePair<string, string> keyValuePair in list3)
- {
- File.Move(keyValuePair.Key, keyValuePair.Value);
- }
- foreach (KeyValuePair<string, string> 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
- }
- }
- }
|