public void Init(int MaxIndex, SaveDataType DataType, string ProductName, bool BackUpOn = true) { saveDataMaxIndex = MaxIndex; saveDataType = DataType; var filePath = $"{Application.persistentDataPath}/{ProductName}/"; //ディレクトリー存在しなければ、作成する if (!string.IsNullOrEmpty(filePath) && !Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } backUpOn = BackUpOn; pathDict = new Dictionary <int, string>(); bkPathDict = new Dictionary <int, string>(); //ファイルパスをセット for (int i = 0; i < MaxIndex; i++) { var path = DataType == SaveDataType.Binary ? $"{filePath}{BaseFileName}_{i}" : $"{filePath}{BaseFileName}_{i}.txt"; var bkPath = DataType == SaveDataType.Binary ? $"{filePath}{BaseFileName}_{i}_BackUp" : $"{filePath}{BaseFileName}_{i}_BackUp.txt"; pathDict.Add(i, path); bkPathDict.Add(i, bkPath); } }
/// <summary> /// Load the mod save data. Loads the save data from {UserIO.GetSavePath("Saves")}/{SaveData.GetFilename(index)}-modsave-{Metadata.Name}.celeste by default. /// </summary> public virtual void LoadSaveData(int index) { if (SaveDataType == null) { return; } _SaveData = (EverestModuleSaveData)SaveDataType.GetConstructor(Everest._EmptyTypeArray).Invoke(Everest._EmptyObjectArray); _SaveData.Index = index; string path = patch_UserIO.GetSaveFilePath(patch_SaveData.GetFilename(index) + "-modsave-" + Metadata.Name); if (!File.Exists(path)) { return; } try { using (Stream stream = File.OpenRead(path)) { if (_SaveData is EverestModuleBinarySaveData) { using (BinaryReader reader = new BinaryReader(stream)) ((EverestModuleBinarySaveData)_SaveData).Read(reader); } else { using (StreamReader reader = new StreamReader(stream)) YamlHelper.DeserializerUsing(_SaveData).Deserialize(reader, SaveDataType); } } _SaveData.Index = index; } catch { } }
public static ResultCode LoadSaveDataFileSystem(ServiceCtx context, bool readOnly, out IFileSystem loadedFileSystem) { loadedFileSystem = null; SaveSpaceId saveSpaceId = (SaveSpaceId)context.RequestData.ReadInt64(); ulong titleId = context.RequestData.ReadUInt64(); UInt128 userId = context.RequestData.ReadStruct <UInt128>(); long saveId = context.RequestData.ReadInt64(); SaveDataType saveDataType = (SaveDataType)context.RequestData.ReadByte(); SaveInfo saveInfo = new SaveInfo(titleId, saveId, saveDataType, saveSpaceId, userId); string savePath = context.Device.FileSystem.GetSavePath(context, saveInfo); try { LocalFileSystem fileSystem = new LocalFileSystem(savePath); LibHac.Fs.IFileSystem saveFileSystem = new DirectorySaveDataFileSystem(fileSystem); if (readOnly) { saveFileSystem = new ReadOnlyFileSystem(saveFileSystem); } loadedFileSystem = new IFileSystem(saveFileSystem); } catch (HorizonResultException ex) { return((ResultCode)ex.ResultValue.Value); } return(ResultCode.Success); }
public long LoadSaveDataFileSystem(ServiceCtx context) { SaveSpaceId saveSpaceId = (SaveSpaceId)context.RequestData.ReadInt64(); long titleId = context.RequestData.ReadInt64(); UInt128 userId = context.RequestData.ReadStruct <UInt128>(); long saveId = context.RequestData.ReadInt64(); SaveDataType saveDataType = (SaveDataType)context.RequestData.ReadByte(); SaveInfo saveInfo = new SaveInfo(titleId, saveId, saveDataType, userId, saveSpaceId); string savePath = context.Device.FileSystem.GetGameSavePath(saveInfo, context); try { LocalFileSystem fileSystem = new LocalFileSystem(savePath); DirectorySaveDataFileSystem saveFileSystem = new DirectorySaveDataFileSystem(fileSystem); MakeObject(context, new IFileSystem(saveFileSystem)); } catch (HorizonResultException ex) { return(ex.ResultValue.Value); } return(0); }
public static T Load <T>(string name = "save", string filePath = "/", string extension = "json", SaveDataType dataType = SaveDataType.Json, bool fireEvents = true, bool throwExceptions = false) { var fullFilepath = BuildFullFilepath(filePath, name, extension); var successful = false; try { if (File.Exists(fullFilepath)) { T obj; switch (dataType) { default: throw new NotImplementedException( $"The selected SaveDataType '{dataType.ToString()}' is not implemented"); case SaveDataType.Json: var json = File.ReadAllText(fullFilepath); obj = JsonConvert.DeserializeObject <T>(json); break; case SaveDataType.Binary: var formatter = new BinaryFormatter(); var file = File.Open(fullFilepath, FileMode.Open); file.Position = 0; obj = (T)formatter.Deserialize(file); file.Close(); break; } successful = true; return(obj); } } catch { if (throwExceptions) { throw; } } finally { if (fireEvents) { if (successful) { OnLoadSuccessful?.Invoke(); } else { OnLoadFailed?.Invoke(); } } } return(default);
public AutofillHintProperties(string autofillHint, SaveDataType saveType, int partitionNumber, IFakeFieldGenerator fakeFieldGenerator, params AutofillType[] validTypes) { mAutofillHint = autofillHint; mSaveType = saveType; mPartition = partitionNumber; mFakeFieldGenerator = fakeFieldGenerator; mValidTypes = new HashSet <AutofillType>(validTypes.ToList()); }
public GameSaveSettings() { _name = "save"; _filePath = "/"; _extension = "json"; _dataType = SaveDataType.Json; _fireEvents = true; _throwExceptions = false; }
public SaveDataAttribute(ProgramId programId, SaveDataType type, UserId userId, ulong saveDataId, ushort index, SaveDataRank rank) { ProgramId = programId; Type = type; UserId = userId; StaticSaveDataId = saveDataId; Index = index; Rank = rank; }
public Result Create(out IFileSystem fileSystem, out ISaveDataExtraDataAccessor extraDataAccessor, IFileSystem sourceFileSystem, ulong saveDataId, bool allowDirectorySaveData, bool useDeviceUniqueMac, SaveDataType type, ITimeStampGenerator timeStampGenerator) { fileSystem = default; extraDataAccessor = default; string saveDataPath = $"/{saveDataId:x16}"; Result rc = sourceFileSystem.GetEntryType(out DirectoryEntryType entryType, saveDataPath); if (rc.IsFailure()) { return(rc == ResultFs.PathNotFound ? ResultFs.TargetNotFound : rc); } switch (entryType) { case DirectoryEntryType.Directory: // Actual FS does this check // if (!allowDirectorySaveData) return ResultFs.InvalidSaveDataEntryType.Log(); var subDirFs = new SubdirectoryFileSystem(sourceFileSystem, saveDataPath); rc = DirectorySaveDataFileSystem.CreateNew(out DirectorySaveDataFileSystem saveFs, subDirFs); if (rc.IsFailure()) { return(rc); } fileSystem = saveFs; // Todo: Dummy ISaveDataExtraDataAccessor return(Result.Success); case DirectoryEntryType.File: rc = sourceFileSystem.OpenFile(out IFile saveDataFile, saveDataPath, OpenMode.ReadWrite); if (rc.IsFailure()) { return(rc); } var saveDataStorage = new DisposingFileStorage(saveDataFile); fileSystem = new SaveDataFileSystem(Keyset, saveDataStorage, IntegrityCheckLevel.ErrorOnInvalid, false); // Todo: ISaveDataExtraDataAccessor return(Result.Success); default: throw new ArgumentOutOfRangeException(); } }
public static void SaveData(float[] pt, int id) { BinaryFormatter formatter = new BinaryFormatter(); string fileName = "/file" + saveFileIndex + ".data"; string path = Application.persistentDataPath + fileName; FileStream stream = new FileStream(path, FileMode.Create); SaveDataType data = new SaveDataType(pt, id); formatter.Serialize(stream, data); stream.Close(); }
public SaveInfo( long TitleId, long SaveId, SaveDataType SaveDataType, UserId UserId, SaveSpaceId SaveSpaceId) { this.TitleId = TitleId; this.UserId = UserId; this.SaveId = SaveId; this.SaveDataType = SaveDataType; this.SaveSpaceId = SaveSpaceId; }
public SaveInfo( long titleId, long saveId, SaveDataType saveDataType, UInt128 userId, SaveSpaceId saveSpaceId) { TitleId = titleId; UserId = userId; SaveId = saveId; SaveDataType = saveDataType; SaveSpaceId = saveSpaceId; }
public SaveInfo( ulong titleId, long saveId, SaveDataType saveDataType, SaveSpaceId saveSpaceId, UserId userId = new UserId()) { TitleId = titleId; SaveId = saveId; SaveDataType = saveDataType; SaveSpaceId = saveSpaceId; UserId = userId; }
public static void Save <T>(T obj, string name = "save", string filePath = "/", string extension = "json", SaveDataType dataType = SaveDataType.Json, bool fireEvents = true, bool throwExceptions = false) { var fullFilepath = BuildFullFilepath(filePath, name, extension); var successful = false; try { switch (dataType) { default: throw new NotImplementedException( $"The selected SaveDataType '{dataType.ToString()}' is not implemented"); case SaveDataType.Json: var json = JsonConvert.SerializeObject(obj, Formatting.Indented); File.WriteAllText(fullFilepath, json); break; case SaveDataType.Binary: var formatter = new BinaryFormatter(); var file = File.Create(fullFilepath); formatter.Serialize(file, obj); file.Close(); break; } successful = true; } catch { if (throwExceptions) { throw; } } finally { if (fireEvents) { if (successful) { OnSaveSuccessful?.Invoke(); } else { OnSaveFailed?.Invoke(); } } } }
private static Result MountSaveDataImpl(this FileSystemClientImpl fs, U8Span mountName, SaveDataSpaceId spaceId, ProgramId programId, UserId userId, SaveDataType type, bool openReadOnly, ushort index) { Result rc = fs.CheckMountName(mountName); if (rc.IsFailure()) { return(rc); } using ReferenceCountedDisposable <IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject(); rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, programId, type, userId, 0, index); if (rc.IsFailure()) { return(rc); } ReferenceCountedDisposable <IFileSystemSf> fileSystem = null; try { if (openReadOnly) { rc = fsProxy.Target.OpenReadOnlySaveDataFileSystem(out fileSystem, spaceId, in attribute); if (rc.IsFailure()) { return(rc); } } else { rc = fsProxy.Target.OpenSaveDataFileSystem(out fileSystem, spaceId, in attribute); if (rc.IsFailure()) { return(rc); } } var fileSystemAdapter = new FileSystemServiceObjectAdapter(fileSystem); return(fs.Fs.Register(mountName, fileSystemAdapter, fileSystemAdapter, null, false, true)); } finally { fileSystem?.Dispose(); } }
public static SaveDataType GetSaveTypeForHints(string[] hints) { SaveDataType saveType = 0; if (hints != null) { foreach (string hint in hints) { if (hint != null && sValidHints.ContainsKey(hint)) { saveType |= sValidHints[hint].GetSaveType(); } } } return(saveType); }
public void DeleteKey(SaveDataType type) { switch (type) { case SaveDataType.Round: ObscuredPrefs.DeleteKey(roundSaveName); break; case SaveDataType.Sound: ObscuredPrefs.DeleteKey(soundSaveName); break; case SaveDataType.UploadScrore: ObscuredPrefs.DeleteKey(uploadScoreSaveName); break; } }
public bool CheckData(SaveDataType type) { switch (type) { case SaveDataType.Round: return(ObscuredPrefs.HasKey(roundSaveName)); case SaveDataType.Sound: return(ObscuredPrefs.HasKey(soundSaveName)); case SaveDataType.UploadScrore: return(ObscuredPrefs.HasKey(uploadScoreSaveName)); default: return(false); } }
public void SaveIntData(SaveDataType type, int value) { switch (type) { case SaveDataType.Round: ObscuredPrefs.SetInt(roundSaveName, value); break; case SaveDataType.Sound: ObscuredPrefs.SetInt(soundSaveName, value); break; case SaveDataType.UploadScrore: ObscuredPrefs.SetInt(uploadScoreSaveName, value); break; } }
/// <summary> /// Load the mod save data. Loads the save data from {Everest.PathSettings}/Save{index}/{Metadata.Name}.yaml by default. /// </summary> public virtual void LoadSaveData(int index) { if (SaveDataType == null) { return; } string path = Path.Combine(Everest.PathSettings, "Save" + index, Metadata.Name + ".yaml"); if (!File.Exists(path)) { _SaveData = (EverestModuleSaveData)SaveDataType.GetConstructor(Everest._EmptyTypeArray).Invoke(Everest._EmptyObjectArray); return; } using (Stream stream = File.OpenRead(path)) using (StreamReader reader = new StreamReader(path)) _SaveData = (EverestModuleSaveData)YamlHelper.Deserializer.Deserialize(reader, SaveDataType); }
public void LoadSaveDataFileSystem(ServiceCtx Context) { SaveSpaceId SaveSpaceId = (SaveSpaceId)Context.RequestData.ReadInt64(); long TitleId = Context.RequestData.ReadInt64(); UserId UserId = new UserId( Context.RequestData.ReadInt64(), Context.RequestData.ReadInt64()); long SaveId = Context.RequestData.ReadInt64(); SaveDataType SaveDataType = (SaveDataType)Context.RequestData.ReadByte(); SaveInfo SaveInfo = new SaveInfo(TitleId, SaveId, SaveDataType, UserId, SaveSpaceId); MakeObject(Context, new IFileSystem(Context.Device.FileSystem.GetGameSavePath(SaveInfo, Context))); }
public void LoadSaveDataFileSystem(ServiceCtx Context) { SaveSpaceId SaveSpaceId = (SaveSpaceId)Context.RequestData.ReadInt64(); long TitleId = Context.RequestData.ReadInt64(); UInt128 UserId = new UInt128( Context.RequestData.ReadInt64(), Context.RequestData.ReadInt64()); long SaveId = Context.RequestData.ReadInt64(); SaveDataType SaveDataType = (SaveDataType)Context.RequestData.ReadByte(); SaveInfo SaveInfo = new SaveInfo(TitleId, SaveId, SaveDataType, UserId, SaveSpaceId); string SavePath = Context.Device.FileSystem.GetGameSavePath(SaveInfo, Context); FileSystemProvider FileSystemProvider = new FileSystemProvider(SavePath, Context.Device.FileSystem.GetBasePath()); MakeObject(Context, new IFileSystem(SavePath, FileSystemProvider)); }
public void LoadSaveDataFileSystem(ServiceCtx context) { SaveSpaceId saveSpaceId = (SaveSpaceId)context.RequestData.ReadInt64(); long titleId = context.RequestData.ReadInt64(); UInt128 userId = new UInt128( context.RequestData.ReadInt64(), context.RequestData.ReadInt64()); long saveId = context.RequestData.ReadInt64(); SaveDataType saveDataType = (SaveDataType)context.RequestData.ReadByte(); SaveInfo saveInfo = new SaveInfo(titleId, saveId, saveDataType, userId, saveSpaceId); string savePath = context.Device.FileSystem.GetGameSavePath(saveInfo, context); FileSystemProvider fileSystemProvider = new FileSystemProvider(savePath, context.Device.FileSystem.GetBasePath()); MakeObject(context, new IFileSystem(savePath, fileSystemProvider)); }
/// <summary> /// Load the mod save data. Loads the save data from {Everest.PathSettings}/Save{index}/{Metadata.Name}.yaml by default. /// </summary> public virtual void LoadSaveData(int index) { if (SaveDataType == null) { return; } _SaveData = (EverestModuleSaveData)SaveDataType.GetConstructor(Everest._EmptyTypeArray).Invoke(Everest._EmptyObjectArray); _SaveData.Index = index; string extension = ".yaml"; if (_SaveData is EverestModuleBinarySaveData) { extension = ".bin"; } string path = Path.Combine(Everest.PathSettings, "Save" + index, Metadata.Name + extension); if (!File.Exists(path)) { return; } try { using (Stream stream = File.OpenRead(path)) { if (_SaveData is EverestModuleBinarySaveData) { // .bin using (BinaryReader reader = new BinaryReader(stream)) ((EverestModuleBinarySaveData)_SaveData).Read(reader); } else { // .yaml using (StreamReader reader = new StreamReader(path)) { _SaveData = (EverestModuleSaveData)YamlHelper.Deserializer.Deserialize(reader, SaveDataType); _SaveData.Index = index; } } } } catch { } }
public static bool IsSharedOpenNeeded(SaveDataType type) { switch (type) { case SaveDataType.System: case SaveDataType.Bcat: case SaveDataType.Temporary: case SaveDataType.Cache: return(false); case SaveDataType.Account: case SaveDataType.Device: return(true); default: Abort.UnexpectedDefault(); return(default); } }
public void LoadSaveDataFileSystem(ServiceCtx context) { SaveSpaceId saveSpaceId = (SaveSpaceId)context.RequestData.ReadInt64(); long titleId = context.RequestData.ReadInt64(); UInt128 userId = new UInt128( context.RequestData.ReadInt64(), context.RequestData.ReadInt64()); long saveId = context.RequestData.ReadInt64(); SaveDataType saveDataType = (SaveDataType)context.RequestData.ReadByte(); SaveInfo saveInfo = new SaveInfo(titleId, saveId, saveDataType, userId, saveSpaceId); string savePath = context.Device.FileSystem.GetGameSavePath(saveInfo, context); LocalFileSystem fileSystem = new LocalFileSystem(savePath); DirectorySaveDataFileSystem saveFileSystem = new DirectorySaveDataFileSystem(fileSystem); MakeObject(context, new IFileSystem(saveFileSystem)); }
public static bool CanUseIndexerReservedArea(SaveDataType type) { switch (type) { case SaveDataType.System: case SaveDataType.SystemBcat: return(true); case SaveDataType.Account: case SaveDataType.Bcat: case SaveDataType.Device: case SaveDataType.Temporary: case SaveDataType.Cache: return(false); default: Abort.UnexpectedDefault(); return(default); } }
public SaveDataFilterInternal(ref SaveDataFilter filter, SaveDataSpaceId spaceId) { this = default; FilterBySaveDataSpaceId = true; SpaceId = spaceId; Rank = filter.Rank; if (filter.FilterByTitleId) { FilterByTitleId = true; TitleId = filter.TitleId; } if (filter.FilterBySaveDataType) { FilterBySaveDataType = true; SaveDataType = filter.SaveDataType; } if (filter.FilterByUserId) { FilterByUserId = true; UserId = filter.UserId; } if (filter.FilterBySaveDataId) { FilterBySaveDataId = true; SaveDataId = filter.SaveDataId; } if (filter.FilterByIndex) { FilterByIndex = true; Index = filter.Index; } }
public int GetIntData(SaveDataType type) { if (CheckData(type) == false) { return(0); } switch (type) { case SaveDataType.Round: return(ObscuredPrefs.GetInt(roundSaveName)); case SaveDataType.Sound: return(ObscuredPrefs.GetInt(soundSaveName)); case SaveDataType.UploadScrore: return(ObscuredPrefs.GetInt(uploadScoreSaveName)); default: return(0); } }
public SaveLoadRepository(GameObject gameObject, SaveDataType saveDataType) { _gameObject = gameObject; switch (saveDataType) { case SaveDataType.playerPrefsData: _data = new PlayerPrefsData(); break; case SaveDataType.jsonData: _data = new JsonData(); break; case SaveDataType.xmlData: _data = new XMLData(); break; } _path = Path.Combine(Application.dataPath, _folderName); Debug.Log("Path = " + _path); }
/// <summary> /// コンストラクタ /// </summary> /// <param name="path">セーブデータのファイルパス</param> public AdvSaveData(SaveDataType type, string path) { this.type = type; this.path = path; }