| 1 |
#include "defextern.h" |
| 2 |
|
| 3 |
#ifndef STRICT |
| 4 |
#define STRICT |
| 5 |
#endif |
| 6 |
#include <stdio.h> |
| 7 |
#include <stdlib.h> |
| 8 |
#include <iostream.h> |
| 9 |
#include <fstream.h> |
| 10 |
#include <windows.h> |
| 11 |
#include <commdlg.h> |
| 12 |
#include "resource.h" |
| 13 |
#include "file.h" |
| 14 |
#include "Mes.h" |
| 15 |
#include "initial.h" |
| 16 |
|
| 17 |
//hFile |
| 18 |
OPENFILENAME ofn; |
| 19 |
#define ExtLen 6 |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
//----------------------------------------------------------------------- |
| 25 |
// |
| 26 |
|
| 27 |
void PopFileInitialize (HWND hwnd) |
| 28 |
{ |
| 29 |
static TCHAR szFilter[] = TEXT ("Ž©“® (*.tfa)\0*.tfa\0") \ |
| 30 |
TEXT ("All Files (*.*)\0*.*\0\0") ; |
| 31 |
|
| 32 |
ofn.lStructSize = sizeof (OPENFILENAME) ; |
| 33 |
ofn.hwndOwner = hwnd ; |
| 34 |
ofn.hInstance = NULL ; |
| 35 |
ofn.lpstrFilter = szFilter ; |
| 36 |
ofn.lpstrCustomFilter = NULL ; |
| 37 |
ofn.nMaxCustFilter = 0 ; |
| 38 |
ofn.nFilterIndex = 0 ; |
| 39 |
ofn.lpstrFile = NULL ; // Set in Open and Close functions |
| 40 |
ofn.nMaxFile = MAX_PATH ; |
| 41 |
ofn.lpstrFileTitle = NULL ; // Set in Open and Close functions |
| 42 |
ofn.nMaxFileTitle = MAX_PATH ; |
| 43 |
ofn.lpstrInitialDir = NULL ; |
| 44 |
ofn.lpstrTitle = NULL ; |
| 45 |
ofn.Flags = 0 ; // Set in Open and Close functions |
| 46 |
ofn.nFileOffset = 0 ; |
| 47 |
ofn.nFileExtension = 0 ; |
| 48 |
ofn.lpstrDefExt = TEXT ("tfa") ; |
| 49 |
ofn.lCustData = 0L ; |
| 50 |
ofn.lpfnHook = NULL ; |
| 51 |
ofn.lpTemplateName = NULL ; |
| 52 |
} |
| 53 |
|
| 54 |
void setOpenFileExtTs1() |
| 55 |
{ |
| 56 |
static TCHAR szFilterTs1[] = TEXT ("ts1 Files (*.ts1)\0*.ts1\0") \ |
| 57 |
TEXT ("All Files (*.*)\0*.*\0\0") ; |
| 58 |
ofn.lpstrFilter = szFilterTs1 ; |
| 59 |
strcpy("ts1",ofn.lpstrDefExt ); |
| 60 |
} |
| 61 |
|
| 62 |
//----------------------------------------------------------------------- |
| 63 |
// |
| 64 |
|
| 65 |
BOOL PopFileOpenDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName) |
| 66 |
{ |
| 67 |
ofn.hwndOwner = hwnd ; |
| 68 |
ofn.lpstrFile = pstrFileName ; |
| 69 |
ofn.lpstrFileTitle = pstrTitleName ; |
| 70 |
ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT ; |
| 71 |
|
| 72 |
return GetOpenFileName (&ofn) ; |
| 73 |
} |
| 74 |
|
| 75 |
//................................... |
| 76 |
// “¯‚¶Šg’£Žq‚Å�V‚µ‚¢ƒtƒ@ƒCƒ‹–¼‚ð�ì‚é |
| 77 |
|
| 78 |
|
| 79 |
void makenewfilename(char *filename,char *newfile,char *new_ad) |
| 80 |
{ |
| 81 |
char ext[ExtLen]=""; |
| 82 |
char *pB; |
| 83 |
wsprintf(newfile,"%s",filename); |
| 84 |
pB=strrchr(newfile,'.'); |
| 85 |
if(pB!=NULL) |
| 86 |
{ |
| 87 |
wsprintf(ext,"%s",pB+1); |
| 88 |
wsprintf(pB,"%s.%s",new_ad,ext); |
| 89 |
} |
| 90 |
else wsprintf(newfile,"%s%s.%s",filename,new_ad,ext); |
| 91 |
} |
| 92 |
|
| 93 |
//................................... |
| 94 |
// “¯‚¶Šg’£Žq‚Å�V‚µ‚¢ƒtƒ@ƒCƒ‹–¼‚ð�ì‚é�A˜A”Ô—p,max999 |
| 95 |
|
| 96 |
|
| 97 |
void makenewfilename(char *filename,char *newfile,DWORD num) |
| 98 |
{ |
| 99 |
char nm[ExtLen]; |
| 100 |
wsprintf(nm,"_%03d",num); |
| 101 |
makenewfilename( filename, newfile, nm); |
| 102 |
} |
| 103 |
|
| 104 |
// ‚·‚łɂ ‚é‚©ƒ`ƒFƒbƒN‚µ‚‚˜A”Ôƒtƒ@ƒCƒ‹�ì�¬ |
| 105 |
// ‚ ‚Á‚½‚ç1�i‚ß‚é |
| 106 |
// numƒfƒtƒHƒ‹ƒg‚Í‚O |
| 107 |
|
| 108 |
void makenewfilenameEx(char *filename,char *newfile, DWORD num) |
| 109 |
{ |
| 110 |
while(1) |
| 111 |
{ |
| 112 |
makenewfilename( filename, newfile, num); |
| 113 |
if( !exist(newfile) ) break; |
| 114 |
num++; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
//................................... |
| 120 |
// ƒtƒ@ƒCƒ‹–¼�A�”Žšƒ`ƒFƒbƒN |
| 121 |
|
| 122 |
BOOL checkfilename(char *filename,char *nextfile) |
| 123 |
{ |
| 124 |
char buff[MAX_PATH]; |
| 125 |
ifstream in; |
| 126 |
char ext[ExtLen]=""; |
| 127 |
ULONG num=0; |
| 128 |
char *pB; |
| 129 |
wsprintf(buff,filename); |
| 130 |
pB=strrchr(buff,'_'); |
| 131 |
if(pB!=NULL) *pB='\0'; |
| 132 |
pB=strrchr(filename,'_'); |
| 133 |
if(pB!=NULL) |
| 134 |
{ |
| 135 |
pB++; |
| 136 |
wsprintf(nextfile,pB); |
| 137 |
pB=strrchr(nextfile,'.'); |
| 138 |
wsprintf(ext,pB+1); |
| 139 |
*pB='\0'; |
| 140 |
sscanf(nextfile,"%d",&num); |
| 141 |
wsprintf(nextfile,"%s_%03d.%s",buff,num+1,ext); |
| 142 |
in.open(nextfile,ios::binary | ios::nocreate); |
| 143 |
if(!in) |
| 144 |
{ |
| 145 |
num=0; |
| 146 |
wsprintf(nextfile,filename); |
| 147 |
} |
| 148 |
|
| 149 |
} |
| 150 |
else |
| 151 |
{ |
| 152 |
pB=strrchr(filename,'\\'); |
| 153 |
if(pB!=NULL) pB++; |
| 154 |
else pB=filename; |
| 155 |
sscanf(pB,"%s",nextfile); |
| 156 |
} |
| 157 |
|
| 158 |
if(num>0) return TRUE; |
| 159 |
else return FALSE; |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
//................................... |
| 164 |
// “¯‚¶ƒtƒHƒ‹ƒ_‚É�V‚µ‚¢ƒtƒ@ƒCƒ‹–¼‚ð�ì‚é |
| 165 |
|
| 166 |
|
| 167 |
void makenewfilename(char *filename,char *newfile,char *new_ad,char *ext) |
| 168 |
{ |
| 169 |
char *pB; |
| 170 |
wsprintf(newfile,"%s",filename); |
| 171 |
pB=strrchr(newfile,'.'); |
| 172 |
if(pB!=NULL) |
| 173 |
{ |
| 174 |
wsprintf(pB,"%s.%s",new_ad,ext); |
| 175 |
} |
| 176 |
else wsprintf(newfile,"%s%s.%s",filename,new_ad,ext); |
| 177 |
} |
| 178 |
|
| 179 |
//‹N“®ƒfƒBƒŒƒNƒgƒŠ |
| 180 |
|
| 181 |
void getini_ex(char*initial) |
| 182 |
{ |
| 183 |
char cdf[MAX_PATH],cddr[MAX_PATH],cddi[MAX_PATH]; |
| 184 |
GetModuleFileName(NULL,cdf,MAX_PATH); |
| 185 |
_splitpath(cdf,cddr,cddi,NULL,NULL); |
| 186 |
wsprintf(initial,"%s\\%s",cddr,cddi); |
| 187 |
} |
| 188 |
|
| 189 |
//ƒfƒBƒŒƒNƒgƒŠ |
| 190 |
|
| 191 |
void getpath(char*file,char *path) |
| 192 |
{ |
| 193 |
char cdf[MAX_PATH],cddr[MAX_PATH],cddi[MAX_PATH]; |
| 194 |
_splitpath(file,cddr,cddi,NULL,NULL); |
| 195 |
wsprintf(path,"%s\\%s",cddr,cddi); |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
//ƒJƒŒƒ“ƒgƒfƒBƒŒƒNƒgƒŠ |
| 200 |
|
| 201 |
void getini_cu(char*initial,char*initialfile) |
| 202 |
{ |
| 203 |
char cd[MAX_PATH]; |
| 204 |
GetCurrentDirectory(MAX_PATH,cd); |
| 205 |
wsprintf(initial,"%s\\%s",cd,initialfile); |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
HANDLE getHandle(char *file) |
| 211 |
{ |
| 212 |
return CreateFile(file,GENERIC_READ,FILE_SHARE_READ,NULL, |
| 213 |
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
char *getExt(char *file) |
| 218 |
{ |
| 219 |
char *p =strrchr(file,'.'); |
| 220 |
if( p++!=NULL) |
| 221 |
if(p!=NULL)return p; |
| 222 |
return NULL; |
| 223 |
} |
| 224 |
|
| 225 |
DWORD getfilesize(char *name) |
| 226 |
{ |
| 227 |
//check length |
| 228 |
DWORD size=0; |
| 229 |
HANDLE f; |
| 230 |
f=getHandle(name); |
| 231 |
if(f!=NULL) |
| 232 |
{ |
| 233 |
size=max(GetFileSize(f,NULL),0); |
| 234 |
CloseHandle(f); |
| 235 |
} |
| 236 |
return size; |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
BOOL checkExt(char *name,char *ext) |
| 241 |
{ |
| 242 |
BOOL f=FALSE; |
| 243 |
char *p; |
| 244 |
if(name ==NULL) return FALSE; |
| 245 |
if(ext ==NULL) return FALSE; |
| 246 |
if(strlen(name)==0 ) return FALSE; |
| 247 |
if(strlen(ext)==0 ) return FALSE; |
| 248 |
p=strrchr(name,'.'); |
| 249 |
if(p!=NULL) |
| 250 |
{ |
| 251 |
p++; |
| 252 |
if(p==NULL) goto end; |
| 253 |
if(strlen(p)==0)goto end; |
| 254 |
if(strlen(p)!=strlen(ext)) ; |
| 255 |
else//toupper |
| 256 |
{ |
| 257 |
//Mes(ext); |
| 258 |
for( int i=0;i<strlen(p);i++) |
| 259 |
if(toupper(p[i])!=toupper(ext[i])) goto end; |
| 260 |
f=TRUE; |
| 261 |
} |
| 262 |
} |
| 263 |
end: |
| 264 |
return f; |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
BOOL checkExts(char *name,char *exts) |
| 269 |
{ |
| 270 |
char ext[ExtsLen]; |
| 271 |
char *p=exts; |
| 272 |
if(p==NULL || name==NULL) return FALSE; |
| 273 |
if(strchr(p,';')==NULL) return checkExt(name,exts); |
| 274 |
BOOL ans =FALSE; |
| 275 |
while(p!=NULL) |
| 276 |
{ |
| 277 |
if(strlen(p)<=1) break; |
| 278 |
strcpy(ext, p); |
| 279 |
if(strchr(ext,';')==NULL) return checkExt(name,ext); |
| 280 |
*strchr(ext,';')=0; |
| 281 |
if(strlen(ext)==0) break; |
| 282 |
if(checkExt(name,ext)) return TRUE; |
| 283 |
p +=strlen(ext); |
| 284 |
if(strlen(p)<=1) break; |
| 285 |
p++; |
| 286 |
} |
| 287 |
return FALSE; |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
#define MAX_PATH 1000 |
| 293 |
#define LEN 1024*512 // |
| 294 |
unsigned long maxi=2147483648-1; |
| 295 |
|
| 296 |
int cutcopy(char *fr, char *to, DWORD from, DWORD len) |
| 297 |
{ |
| 298 |
char b; |
| 299 |
char buf[LEN]; |
| 300 |
unsigned long i,num; |
| 301 |
DWORD maxi; |
| 302 |
|
| 303 |
ifstream in(fr,ios::binary|ios::nocreate); |
| 304 |
if(!in) {return 0;} |
| 305 |
|
| 306 |
ofstream ou(to,ios::binary); |
| 307 |
if(!ou) {return 0;} |
| 308 |
|
| 309 |
in.seekg(from,ios::beg); |
| 310 |
if(!in) {return 0;} |
| 311 |
|
| 312 |
if(len>0 || len>LEN) maxi=len; |
| 313 |
|
| 314 |
i=0; |
| 315 |
num=0; |
| 316 |
while(1) |
| 317 |
{ |
| 318 |
memset(buf,0,LEN); |
| 319 |
in.read(buf,LEN); |
| 320 |
num =in.gcount(); |
| 321 |
if(num==0) break; |
| 322 |
if(maxi >= LEN) |
| 323 |
{ |
| 324 |
ou.write(buf,num); |
| 325 |
maxi-=num; |
| 326 |
i+=num; |
| 327 |
} |
| 328 |
else |
| 329 |
{ |
| 330 |
ou.write(buf,min(num,maxi)); |
| 331 |
i+=min(num,maxi); |
| 332 |
break; |
| 333 |
} |
| 334 |
//setstatusnum(i); |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
// ƒtƒ@ƒCƒ‹ƒŠƒXƒg “Ç‚Ý�ž‚Ý–{‘Ì |
| 341 |
// �I—¹ƒR�[ƒh‚Í _END, _FILE, _FOLDER |
| 342 |
|
| 343 |
int getnextfile(char *dir, char *filter, char *file,int reset) |
| 344 |
{ |
| 345 |
char szfname[MAX_PATH + 5],szfnameback[MAX_PATH + 5]; |
| 346 |
WIN32_FIND_DATA wfd; |
| 347 |
static HANDLE hFind; |
| 348 |
|
| 349 |
static int ans = 0; |
| 350 |
SYSTEMTIME localtm; |
| 351 |
FILETIME localft; |
| 352 |
char szBuf[MAX_PATH]; |
| 353 |
BOOL rootflag=FALSE; |
| 354 |
|
| 355 |
if(reset==_closeOnly) |
| 356 |
{ |
| 357 |
ans =0; |
| 358 |
if( hFind !=NULL) FindClose(hFind); |
| 359 |
return _END; |
| 360 |
} |
| 361 |
if(strlen(dir)<4) rootflag=TRUE;//ƒ‹�[ƒg‚©ƒ`ƒFƒbƒN�@Žè”²‚« |
| 362 |
SetCurrentDirectory(dir); |
| 363 |
|
| 364 |
if(reset==0) ans =0; |
| 365 |
if(ans ==0) |
| 366 |
{ |
| 367 |
hFind = FindFirstFile(filter, &wfd); |
| 368 |
if (hFind == INVALID_HANDLE_VALUE) { |
| 369 |
FindClose(hFind); |
| 370 |
return _END; |
| 371 |
} |
| 372 |
else { |
| 373 |
strcpy(szfname, wfd.cFileName); |
| 374 |
strcpy(file, wfd.cFileName); |
| 375 |
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
| 376 |
{ |
| 377 |
ans =_FOLDER; |
| 378 |
} |
| 379 |
else |
| 380 |
{ |
| 381 |
ans =_FILE; |
| 382 |
} |
| 383 |
return ans; |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
if (FindNextFile(hFind, &wfd)) { |
| 388 |
strcpy(szfname, wfd.cFileName); |
| 389 |
strcpy(file, wfd.cFileName); |
| 390 |
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
| 391 |
{ |
| 392 |
ans =_FOLDER; |
| 393 |
} |
| 394 |
else |
| 395 |
{ |
| 396 |
ans =_FILE; |
| 397 |
} |
| 398 |
return ans; |
| 399 |
} |
| 400 |
else |
| 401 |
{ |
| 402 |
FindClose(hFind); |
| 403 |
return _END; |
| 404 |
} |
| 405 |
return ans; |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
ofstream GetStream(char *file, char *path, ofstream &ou,int st) |
| 410 |
{ |
| 411 |
char dir[MAX_PATH]; |
| 412 |
GetCurrentDirectory(MAX_PATH,dir); |
| 413 |
SetCurrentDirectory( path); |
| 414 |
ou.open( file ,st ); |
| 415 |
SetCurrentDirectory( dir); |
| 416 |
return ou; |
| 417 |
} |
| 418 |
|
| 419 |
char *GetFullName(char *full, char *file, char *path, DWORD len) |
| 420 |
{ |
| 421 |
char dir[MAX_PATH]; |
| 422 |
GetCurrentDirectory(MAX_PATH,dir); |
| 423 |
SetCurrentDirectory( path); |
| 424 |
_fullpath( full,file, len); |
| 425 |
SetCurrentDirectory( dir); |
| 426 |
return full; |
| 427 |
} |
| 428 |
|
| 429 |
char *quote( char *file) |
| 430 |
{ |
| 431 |
char buff[1000]; |
| 432 |
char *p=buff; |
| 433 |
char *f=file; |
| 434 |
strcpy(p,file); |
| 435 |
*f++ ='\"'; |
| 436 |
while(*p!=0) {*f++ = *p++; } |
| 437 |
*f++ ='\"'; |
| 438 |
*f='\0'; |
| 439 |
|
| 440 |
return file; |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
// ƒtƒ@ƒCƒ‹‚ª‘¶�Ý‚·‚é‚© |
| 445 |
|
| 446 |
BOOL exist(char *file) |
| 447 |
{ |
| 448 |
ifstream in(file ,ios::nocreate); |
| 449 |
if(!in) return FALSE; |
| 450 |
return TRUE; |
| 451 |
} |