public EraDataResult CheckData(int saveIndex, EraSaveFileType type) { string filename = null; switch (type) { case EraSaveFileType.Normal: filename = getSaveDataPath(saveIndex); break; case EraSaveFileType.Global: filename = getSaveDataPathG(); break; case EraSaveFileType.Var: filename = getSaveDataPathV(saveIndex); break; case EraSaveFileType.CharVar: filename = getSaveDataPathC(saveIndex); break; } EraDataResult result = new EraDataResult(); if (!File.Exists(filename)) { result.State = EraDataState.FILENOTFOUND; result.DataMes = "----"; return result; } FileStream fs = null; EraBinaryDataReader bReader = null; EraDataReader reader = null; Int64 version = 0; try { fs = new FileStream(filename, FileMode.Open, FileAccess.Read); bReader = EraBinaryDataReader.CreateReader(fs); if (bReader == null)//eramaker形式 { reader = new EraDataReader(fs); if (!gamebase.UniqueCodeEqualTo(reader.ReadInt64())) { result.State = EraDataState.GAME_ERROR; result.DataMes = "異なるゲームのセーブデータです"; return result; } version = reader.ReadInt64(); if (!gamebase.CheckVersion(version)) { result.State = EraDataState.VIRSION_ERROR; result.DataMes = "セーブデータのバーションが異なります"; return result; } result.State = EraDataState.OK; result.DataMes = reader.ReadString(); return result; //result.State = EraDataState.ETC_ERROR; //result.DataMes = "セーブデータが壊れています"; //return result; } EraSaveFileType fileType = bReader.ReadFileType(); if (type != fileType) { result.State = EraDataState.ETC_ERROR; result.DataMes = "セーブデータが壊れています"; return result; } if (!gamebase.UniqueCodeEqualTo(bReader.ReadInt64())) { result.State = EraDataState.GAME_ERROR; result.DataMes = "異なるゲームのセーブデータです"; return result; } version = bReader.ReadInt64(); if (!gamebase.CheckVersion(version)) { result.State = EraDataState.VIRSION_ERROR; result.DataMes = "セーブデータのバーションが異なります"; return result; } result.State = EraDataState.OK; result.DataMes = bReader.ReadString(); return result; } catch (FileEE fee) { result.State = EraDataState.ETC_ERROR; result.DataMes = fee.Message; } catch (Exception) { result.State = EraDataState.ETC_ERROR; result.DataMes = "読み込み中にエラーが発生しました"; } finally { if (reader != null) reader.Close(); else if (bReader != null) bReader.Close(); else if (fs != null) fs.Close(); } return result; }
public void LoadFromStream(EraDataReader reader) { if (!gamebase.UniqueCodeEqualTo(reader.ReadInt64())) throw new FileEE("異なるゲームのセーブデータです"); Int64 version = reader.ReadInt64(); if (!gamebase.CheckVersion(version)) throw new FileEE("セーブデータのバーションが異なります"); string text = reader.ReadString();//PUTFORM varData.SetDefaultValue(constant); varData.SetDefaultLocalValue(); varData.LastLoadVersion = version; //varData.LastLoadNo = dataIndex; varData.LastLoadText = text; int charaCount = (int)reader.ReadInt64(); varData.CharacterList.Clear(); for (int i = 0; i < charaCount; i++) { CharacterData chara = new CharacterData(constant); varData.CharacterList.Add(chara); chara.LoadFromStream(reader); } varData.LoadFromStream(reader); if (reader.SeekEmuStart()) { if (reader.DataVersion < 1803)//キャラ2次元配列追加以前 for (int i = 0; i < charaCount; i++) varData.CharacterList[i].LoadFromStreamExtended_Old1802(reader); else for (int i = 0; i < charaCount; i++) varData.CharacterList[i].LoadFromStreamExtended(reader); varData.LoadFromStreamExtended(reader, reader.DataVersion); } }
public bool LoadGlobal() { string filepath = getSaveDataPathG(); if (!File.Exists(filepath)) return false; EraDataReader reader = null; EraBinaryDataReader bReader = null; FileStream fs = null; try { fs = new FileStream(filepath, FileMode.Open, FileAccess.Read); bReader = EraBinaryDataReader.CreateReader(fs); if (bReader != null) { EraSaveFileType fileType = bReader.ReadFileType(); if (fileType != EraSaveFileType.Global) return false; if (!gamebase.UniqueCodeEqualTo(bReader.ReadInt64())) return false; Int64 version = bReader.ReadInt64(); if (!gamebase.CheckVersion(version)) return false; bReader.ReadString();//saveMes varData.LoadFromStreamBinary(bReader); } else { reader = new EraDataReader(fs); if (!gamebase.UniqueCodeEqualTo(reader.ReadInt64())) return false; Int64 version = reader.ReadInt64(); if (!gamebase.CheckVersion(version)) return false; varData.LoadGlobalFromStream(reader); if (reader.SeekEmuStart()) { varData.LoadGlobalFromStream1808(reader); } } return true; } catch { return false; } finally { if (reader != null) reader.Close(); else if (bReader != null) bReader.Close(); else if (fs != null) fs.Close(); } }
public bool LoadFrom(int dataIndex) { string filepath = getSaveDataPath(dataIndex); if (!File.Exists(filepath)) throw new ExeEE("存在しないパスを呼び出した"); EraDataReader reader = null; EraBinaryDataReader bReader = null; FileStream fs = null; try { fs = new FileStream(filepath, FileMode.Open, FileAccess.Read); bReader = EraBinaryDataReader.CreateReader(fs); if (bReader != null) { LoadFromStreamBinary(bReader); } else { reader = new EraDataReader(fs); LoadFromStream(reader); } varData.LastLoadNo = dataIndex; } finally { if (reader != null) reader.Close(); else if (bReader != null) bReader.Close(); else if (fs != null) fs.Close(); } return true; }