• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisión6f1d34948fd66ea998b671bbd3029d9818321624 (tree)
Tiempo2017-05-09 22:56:53
Autoryyagi <yyagi.dtxmania@gmai...>
Commiteryyagi

Log Message

#36500 書き込み最小化のクラスを作り直した。従来はsongs.db等で正しく書き込みがなされない(文字列の前に文字数の情報が出力されていない)問題があったが、これを修正している。
#xxxxx タイトルバーにマウスカーソルを合わせている場合は、マウスカーソルを消去しないようにした。

Cambiar Resumen

  • delete: "DTXMania\343\203\227\343\203\255\343\202\270\343\202\247\343\202\257\343\203\210/\343\202\263\343\203\274\343\203\211/\343\202\271\343\202\263\343\202\242\343\200\201\346\233\262/CSong\347\256\241\347\220\206.cs"
  • delete: "DTXMania\343\203\227\343\203\255\343\202\270\343\202\247\343\202\257\343\203\210/\343\202\263\343\203\274\343\203\211/\345\205\250\344\275\223/CDTXMania.cs"
  • delete: "DTXMania\343\203\227\343\203\255\343\202\270\343\202\247\343\202\257\343\203\210/\343\202\263\343\203\274\343\203\211/\345\205\250\344\275\223/FileStreamSSD.cs"

Diferencia incremental

--- "a/DTXMania\343\203\227\343\203\255\343\202\270\343\202\247\343\202\257\343\203\210/\343\202\263\343\203\274\343\203\211/\343\202\271\343\202\263\343\202\242\343\200\201\346\233\262/CSong\347\256\241\347\220\206.cs"
+++ "b/DTXMania\343\203\227\343\203\255\343\202\270\343\202\247\343\202\257\343\203\210/\343\202\263\343\203\274\343\203\211/\343\202\271\343\202\263\343\202\242\343\200\201\346\233\262/CSong\347\256\241\347\220\206.cs"
@@ -1082,8 +1082,8 @@ namespace DTXMania
10821082 this.nSongsDBへ出力できたスコア数 = 0;
10831083 try
10841084 {
1085- BinaryWriter bw = new BinaryWriter( new FileStream( SongsDBファイル名, FileMode.Create, FileAccess.Write ) );
1086- //BinaryWriter bw = new BinaryWriter( new FileStreamSSD( SongsDBファイル名, FileMode.Create, FileAccess.Write ) );
1085+ //BinaryWriter bw = new BinaryWriter( new FileStream( SongsDBファイル名, FileMode.Create, FileAccess.Write ) );
1086+ BinaryWriter bw = new BinaryWriter( new FileStreamSSD( SongsDBファイル名, FileMode.Create, FileAccess.Write ) );
10871087 bw.Write( SONGSDB_VERSION );
10881088 this.tSongsDBにリストを1つ出力する(bw, this.list曲ルート);
10891089 bw.Close();
--- "a/DTXMania\343\203\227\343\203\255\343\202\270\343\202\247\343\202\257\343\203\210/\343\202\263\343\203\274\343\203\211/\345\205\250\344\275\223/CDTXMania.cs"
+++ "b/DTXMania\343\203\227\343\203\255\343\202\270\343\202\247\343\202\257\343\203\210/\343\202\263\343\203\274\343\203\211/\345\205\250\344\275\223/CDTXMania.cs"
@@ -2828,7 +2828,11 @@ namespace DTXMania
28282828 //Trace.TraceInformation("n現在の経過時間ms" + ccMouseShow.n現在の経過時間ms + ", n現在の値=" + ccMouseShow.n現在の値 + ", b終了値に達した=" + ccMouseShow.b終了値に達した);
28292829 if (bマウスカーソル表示中 && ccMouseShow.b終了値に達した)
28302830 {
2831- Hide();
2831+ Point client_point = CDTXMania.Instance.Window.PointToClient(Cursor.Position);
2832+ if (client_point.Y >= 0) // タイトルバー上にマウスカーソルがある場合は、隠さない
2833+ {
2834+ Hide();
2835+ }
28322836 }
28332837
28342838 }
--- "a/DTXMania\343\203\227\343\203\255\343\202\270\343\202\247\343\202\257\343\203\210/\343\202\263\343\203\274\343\203\211/\345\205\250\344\275\223/FileStreamSSD.cs"
+++ "b/DTXMania\343\203\227\343\203\255\343\202\270\343\202\247\343\202\257\343\203\210/\343\202\263\343\203\274\343\203\211/\345\205\250\344\275\223/FileStreamSSD.cs"
@@ -16,8 +16,16 @@ namespace DTXMania
1616 private string _filename;
1717 private FileMode _mode;
1818 private FileAccess _access;
19- private MemoryStream _ms_new = null, _ms_org = null;
19+ private MemoryStream _ms_org = null;
2020 private FileStream _fs;
21+ private bool disposed = false;
22+
23+ /// <summary>
24+ /// (baseではなく)このクラスのClose()が実行されたかどうか
25+ /// </summary>
26+ private bool bClosed = false;
27+
28+
2129
2230 #region [ コンストラクタ ]
2331 public FileStreamSSD()
@@ -26,55 +34,31 @@ namespace DTXMania
2634 }
2735
2836 public FileStreamSSD( string path )
37+ : this(path, FileMode.Create, FileAccess.Write)
2938 {
30-//Trace.TraceInformation( "FileStreamSSD(" + Path.GetFileName(path) + "): Constractor" );
31- Initialize( path, FileMode.Create, FileAccess.Write );
3239 }
3340 public FileStreamSSD( string path, FileMode mode, FileAccess access )
41+ : base()
3442 {
35-//Trace.TraceInformation( "FileStreamSSD(" + Path.GetFileName(path) + ", " + mode.ToString() + ", " + access.ToString() + "): Constractor" );
36- Initialize( path, mode, access );
37- }
38-
39- private void Initialize( string path, FileMode mode, FileAccess access )
40- {
41- if ( mode != FileMode.Create )
43+ if (mode != FileMode.Create)
4244 {
43- throw new ArgumentException( mode.ToString() + "は、FileStreamSSD()でサポートしていません。" );
45+ throw new ArgumentException(mode.ToString() + "は、FileStreamSSD()でサポートしていません。");
4446 }
45- if ( access != FileAccess.Write )
47+ if (access != FileAccess.Write)
4648 {
47- throw new ArgumentException( access.ToString() + "は、FileStreamSSD()でサポートしていません。" );
49+ throw new ArgumentException(access.ToString() + "は、FileStreamSSD()でサポートしていません。");
4850 }
4951 _filename = path;
5052 _mode = mode;
5153 _access = access;
52- _ms_new = new MemoryStream();
5354 }
5455 #endregion
5556
56-
57- /// <summary>
58- /// StreamのWrite。
59- /// </summary>
60- /// <param name="buffer"></param>
61- /// <param name="offset"></param>
62- /// <param name="count"></param>
63- public override void Write( byte[] buffer, int offset, int count )
64- {
65- _ms_new.Write( buffer, offset, count );
66-//if ( Path.GetExtension( _filename ) != ".db" )
67-//{
68-//Debug.Write( "W" );
69-//}
70- }
71-
7257 /// <summary>
7358 /// StreamのClose。元ファイルとのコンペアを行い、一致していればファイルの上書きをしない
7459 /// </summary>
75- public override void Close()
60+ public new void Close()
7661 {
77-Debug.WriteLine( "---" );
7862 bool bSame = true;
7963 Flush();
8064
@@ -82,68 +66,65 @@ Debug.WriteLine( "---" );
8266 if ( !File.Exists( _filename ) )
8367 {
8468 bSame = false;
85-Debug.WriteLine( Path.GetFileName( _filename ) + ": No file exists" );
8669 }
8770 else
8871 // まず、既存ファイルをMemoryStreamにコピー
8972 {
90-Debug.WriteLine( "B2" );
91- using ( _fs = new FileStream( _filename, FileMode.Open, FileAccess.Read ) )
73+ using ( _fs = new FileStream( _filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete ) )
9274 {
93- Debug.WriteLine( "Length old=" + _fs.Length + ", new=" + _ms_new.Length );
9475 // 元ファイルとファイルサイズが異なる場合は、
95- if ( _fs.Length != _ms_new.Length )
76+ if ( _fs.Length != this.Length )
9677 {
9778 bSame = false;
98-Debug.WriteLine( "B2: Set bSame=false" );
9979 }
10080 else
10181 {
102-Debug.WriteLine( "B2: copy from _fs to _ms_org" );
10382 _ms_org = new MemoryStream();
10483 _fs.CopyTo( _ms_org );
10584 }
106- }; // _fs will be closed and disposed here, by using()
85+ };
10786 _fs = null;
10887 }
10988
110-Debug.WriteLine( "C" );
11189 if ( bSame ) // まだ新旧ファイルが一致している可能性があれば...
11290 {
11391 // MemoryStream同士のコンペア
11492 _ms_org.Seek( 0, SeekOrigin.Begin );
115- _ms_new.Seek( 0, SeekOrigin.Begin );
116-
117-Debug.WriteLine( "1" );
118- while (_ms_new.Position < _ms_new.Length )
93+ this.Seek( 0, SeekOrigin.Begin );
94+
95+ try
11996 {
120- int dorg = _ms_org.ReadByte();
121- int dnew = _ms_new.ReadByte();
122- if (dorg != dnew)
97+ while (this.Position < this.Length)
12398 {
124- bSame = false;
125- break;
99+ int dorg = _ms_org.ReadByte();
100+ int dnew = this.ReadByte();
101+ if (dorg != dnew)
102+ {
103+ bSame = false;
104+ break;
105+ }
126106 }
127107 }
108+ catch // ファイルサイズが同じ場合のみtry内に来るため、通常ここには来ないはずだが、念のためbSame=false側に倒しておく
109+ {
110+ bSame = false;
111+ }
128112 }
129-Debug.WriteLine( "2: bSame=" + bSame );
130113 if ( _ms_org != null )
131114 {
132115 _ms_org.Close();
133116 _ms_org.Dispose();
134117 _ms_org = null;
135118 }
136-Debug.WriteLine( "3" );
137- _ms_new.Seek( 0, SeekOrigin.Begin );
119+ this.Seek( 0, SeekOrigin.Begin );
138120
139-Debug.WriteLine( "new file length: " + _ms_new.Length );
140121 // 元ファイルと新規ファイルが一致していない場合、新規ファイルで上書きする
141122 if ( !bSame )
142123 {
143124 Trace.TraceInformation( Path.GetFileName( _filename ) + ": 以前のファイルから変化があったため、書き込みを実行します。" );
144125 using ( _fs = new FileStream( _filename, _mode, _access ) )
145126 {
146- _ms_new.CopyTo( _fs );
127+ this.CopyTo( _fs );
147128 } // _fs will be closed and disposed, by using()
148129 _fs = null;
149130 }
@@ -151,11 +132,9 @@ Debug.WriteLine( "new file length: " + _ms_new.Length );
151132 {
152133 Trace.TraceInformation( Path.GetFileName( _filename ) + ": 以前のファイルから変化がなかったため、書き込みを行いません。" );
153134 }
154- _ms_new.Close();
155- _ms_new.Dispose();
156- _ms_new = null;
157135
158- //base.Close();
136+ bClosed = true; // base.Close()の前にフラグ変更のこと。さもないと、無限に再帰実行される
137+ Dispose();
159138 }
160139
161140
@@ -168,23 +147,34 @@ Debug.WriteLine( "new file length: " + _ms_new.Length );
168147 GC.SuppressFinalize( this );
169148 base.Dispose();
170149 }
171- protected override void Dispose( bool bManagedDispose )
150+ protected override void Dispose( bool disposing)
172151 {
173- if ( this._ms_new != null )
174- {
175- this.Close(); // Close()する前にDispose()された場合用 (DataContractSerializer経由だと、ここに来る)
176- //this._ms_new.Dispose(); // Close()内でDisposeとnullクリアがなされるため、Disposeはしない
177- //this._ms_new = null; //
178- }
179- if ( this._ms_org != null )
152+ if (!this.disposed)
180153 {
181- this._ms_org.Dispose();
182- this._ms_org = null;
183- }
184- if ( this._fs != null )
185- {
186- this._fs.Dispose();
187- this._fs = null;
154+ try
155+ {
156+ if (this._ms_org != null)
157+ {
158+ this._ms_org.Close();
159+ this._ms_org.Dispose();
160+ this._ms_org = null;
161+ }
162+ if (this._fs != null)
163+ {
164+ this._fs.Close();
165+ this._fs.Dispose();
166+ this._fs = null;
167+ }
168+ if (!bClosed)
169+ {
170+ this.Close(); // Close()なしでDispose()された場合用 (DataContractSerializer経由だと、ここに来る)
171+ }
172+ this.disposed = true;
173+ }
174+ finally
175+ {
176+ base.Dispose(disposing);
177+ }
188178 }
189179 }
190180 ~FileStreamSSD()