Differences From Artifact [3b6f189d5603825c]:
- File
src/bga_melter.d
- 2015-04-21 10:46:55 - part of checkin [4e2933c620] on branch trunk - Rebased to the latest verson dmd 2.067. Not yet verified the outcome. (user: kinaba) [annotate]
To Artifact [cf24a8abe2b880fc]:
- File
src/bga_melter.d
- 2015-04-30 23:29:51 - part of checkin [ab3b073ef6] on branch trunk - private import => import (since in the latest D it is the default.) (user: kinaba) [annotate]
1 -private import win32.windows;
2 -private import std.string;
3 -private import std.file;
4 -private import std.c.stdio;
5 -private import std.string;
6 -private import etc.c.zlib;
7 -private import libbz2.bzlib;
8 -private import util;
1 +import win32.windows;
2 +import std.c.stdio;
3 +import std.file;
4 +import std.string;
5 +import etc.c.zlib;
6 +import libbz2.bzlib;
7 +import util;
9 8
10 9 //----------------------------------------------------------------
11 10 // Bga書庫のファイルヘッダ形式
12 11 //----------------------------------------------------------------
13 12
14 13 align(1) struct BgaHeader
15 14 {
................................................................................
93 92 class Filep
94 93 {
95 94 private FILE* fp;
96 95 private this( FILE* p ) { fp = p; }
97 96
98 97 static Filep open( string filename, bool read )
99 98 {
100 - FILE* fp = fopen( toStringz(filename), read?"rb":"wb" );
99 + FILE* fp = fopen(filename.toStringz(), read?"rb":"wb");
101 100 return (fp ? new Filep(fp) : null);
102 101 }
103 102
104 103 int dup_han()
105 104 {
106 105 int fd = dup( fileno(fp) );
107 106 lseek( fd, cur(), 0 );
................................................................................
153 152 //----------------------------------------------------------------
154 153 // メインクラス
155 154 //----------------------------------------------------------------
156 155
157 156 class BgaMelter
158 157 {
159 158 alias BgaAnswer delegate(ref BgaHeader) FileHandler;
160 - alias BgaAnswer delegate(int, int) ProgressHandler;
159 + alias BgaAnswer delegate(int, int) ProgressHandler;
161 160
162 161 private Filep fp = null;
163 162
164 163 this( string arc_name )
165 164 {
166 165 fp = Filep.open( arc_name, true );
167 166 if( fp is null )
................................................................................
213 212 bContinue = GzDec( hdr.compressed_size, hdr.original_size, outf, ph );
214 213 else if( hdr.method == "BZ2\0" )
215 214 bContinue = BzDec( hdr.original_size, outf, ph );
216 215
217 216 // 閉じて属性設定
218 217 outf.close();
219 218 dosSetFTime( hdr.fname, hdr.date, hdr.time );
220 - SetFileAttributesA( toStringz(hdr.fname), hdr.attrib );
219 + SetFileAttributesA( hdr.fname.toStringz(), hdr.attrib );
221 220 if( !bContinue )
222 221 return;
223 222 }
224 223 finally { fp.seek_to(nextpos); }
225 224 }
226 225 }
227 226 finally { close(); }
................................................................................
284 283 if( hdr.arc_type==2 )
285 284 return false;
286 285 if( hdr.arc_type==0 && hdr.compressed_size==hdr.original_size )
287 286 {
288 287 int x = hdr.fname.lastIndexOf('.');
289 288 if( x == -1 )
290 289 return true;
291 - string ext = toLower(hdr.fname[x+1 .. $]);
290 + string ext = hdr.fname[x+1 .. $].toLower();
292 291 if( ext=="arc" || ext=="arj" || ext=="bz2" || ext=="bza"
293 292 || ext=="cab" || ext=="gz" || ext=="gza" || ext=="lzh"
294 293 || ext=="lzs" || ext=="pak" || ext=="rar" || ext=="taz"
295 294 || ext=="tbz" || ext=="tgz" || ext=="z" || ext=="zip"
296 295 || ext=="zoo" )
297 296 return false;
298 297 }
299 298 return true;
300 299 }
301 300
302 301 static string pathMake( string path )
303 302 {
304 - char* ps = cast(char*)toStringz(path);
305 - for(char* p=ps;;)
303 + char* ps = cast(char*)path.toStringz();
304 + for(char* p=ps;; ++p)
306 305 {
307 306 for(; *p!=0&&*p!='\\'&&*p!='/'; p=CharNextA(p)) {}
308 307 if( *p==0 )
309 308 break;
310 - CreateDirectoryA( toStringz(ps[0..(p-ps)]), null );
311 - ++p;
309 + CreateDirectoryA( ps[0..(p-ps)].toStringz(), null );
312 310 }
313 311 return path;
314 312 }
315 313
316 - enum { BUFSIZ = 65536 }
314 + enum BUFSIZ = 65536;
317 315
318 316 private bool NcDec( uint usiz, Filep outf, ProgressHandler ph )
319 317 {
320 318 uint init_usiz = usiz;
321 319
322 320 // 非圧縮。コピーするだけ
323 321 while( usiz )