Artifact f4a72491493dc9ab440223d8350f75cc3936c50d
- File
src/util.d
-
2015-05-05 06:49:05
- part of checkin
[9b639cf2d6]
on branch trunk
- Working version for update to 2.067.
The problem was __gshared. Replacing it with TLS fixed the issue. Remaining problem is that "hack.d"'s CloseHandle hack is not working anymore.
(user: kinaba) [annotate]
-
2015-05-05 06:49:05
- part of checkin
[9b639cf2d6]
on branch trunk
- Working version for update to 2.067.
import win32.windows; import std.string; import std.file; char lastChar( string s ) { return *CharPrevA(cast(char*)s.ptr, cast(char*)s.ptr+s.length); } //---------------------------------------------------------------- // コマンドライン解析 //---------------------------------------------------------------- string[] cmd_parse( string str, bool in_resp=false ) { string[] ans; char resp_char = '@'; for(int i=0; i!=str.length; ) { // 空白スキップ while( i!=str.length && 0<=str[i] && str[i]<=' ' ) ++i; if( i == str.length ) break; // ""を考慮して一個パラメタ切り出し string param; if( str[i] == '"' ) { int j = ++i; while( j!=str.length ) { if( str[j]=='"' && (j+1==str.length || 0<=str[j+1] && str[j+1]<=' ') ) break; ++j; } param = str[i .. j]; i = (j==str.length ? j : j+1); } else { int j=i; while( j!=str.length && (str[j]<0 || ' '<str[j]) ) ++j; param = str[i .. j]; i = j; } // レスポンスファイル関連の処理 if( !in_resp && param[0]==resp_char ) { try { string rsp = cast(string) std.file.read( param[1..$] ); ans ~= cmd_parse(rsp,true); } catch( FileException e ) {} } else if( param.length>=2 && param[0..2]=="--" ) { resp_char = (param.length==2 ? '\0' : param[2]); } else { ans ~= param; // 普通にパラメタ追加 } } return ans; } //---------------------------------------------------------------- // DOS形式でファイル音更新時刻を書き換え //---------------------------------------------------------------- void dosSetFTime( string fname, ushort date, ushort time ) { FILETIME ft,lc; if( DosDateTimeToFileTime( date, time, &lc ) ) if( LocalFileTimeToFileTime( &lc, &ft ) ) { HANDLE han = CreateFileA( toStringz(fname), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,null, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, null ); if( han==INVALID_HANDLE_VALUE ) return; SetFileTime( han,&ft,null,&ft ); CloseHandle( han ); } } //---------------------------------------------------------------- // 指定時刻(DOS形式)より新しいファイルか? //---------------------------------------------------------------- bool newer_than( ushort d1, ushort t1, string fname ) { HANDLE han = CreateFileA( toStringz(fname), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,null, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, null ); if( han==INVALID_HANDLE_VALUE ) return false; FILETIME ft; GetFileTime( han, null, null, &ft ); CloseHandle( han ); FILETIME lc; FileTimeToLocalFileTime( &ft, &lc ); ushort d2, t2; FileTimeToDosDateTime( &lc, &d2, &t2 ); if( d1 < d2 ) return true; if( d1 == d2 ) return (t1 < t2); return false; }