public string SaveTrackItem(out ITrackItemCache nextStatus, string path) { // ファイルを作成してみて保存パス名を決める string fileName = string.Empty; for (int index = 1; index < int.MaxValue; ++index) { fileName = string.Format("TrackItem{0:D4}.dat", index); try { string savePath = Path.Combine(path, fileName); using (Stream stream = new FileStream(savePath, FileMode.CreateNew)) { stream.SetLength(0); stream.Flush(); using (TrackItemWriter tiw = new TrackItemWriter(stream)) { // 保存します tiw.Write(_item); // ファイルが作成できたからこれをファイル名にします。 _fileName = fileName; break; } } } catch (IOException) { // ファイル名が作成できないみたいだらから continue; } } nextStatus = new TrackItemCacheLoaded(_item, _fileName); return(_fileName); }
public TrackItem GetTrackItem(out ITrackItemCache nextStatus) { string filePath = System.IO.Path.Combine(_savePath, _fileName); using (TrackItemReader tir = new TrackItemReader(filePath)) { _item = tir.Read(); } nextStatus = new TrackItemCacheLoaded(_item, _fileName); return(_item); }
public string SaveTrackItem(out ITrackItemCache nextStatus, string path) { // 上書き保存 string savaPath = Path.Combine(path, this._fileName); using (Stream stream = new FileStream(savaPath, FileMode.Create, FileAccess.Write)) { stream.SetLength(0); stream.Flush(); using (TrackItemWriter tiw = new TrackItemWriter(stream)) { // 保存します tiw.Write(_item); } } nextStatus = new TrackItemCacheLoaded(_item, _fileName); return(_fileName); }