source: dev/trunk/ab5.0/abdev/abdev/FileOperation.cpp @ 622

Last change on this file since 622 was 622, checked in by dai_9181, 15 years ago

ResourceManagerクラスを追加。既存のリソース管理モジュールの置き換えを行った。

File size: 16.0 KB
Line 
1#include "stdafx.h"
2
3#include "Common.h"
4
5void MakeUserSettingDir(void){
6    char temporary[MAX_PATH];
7    sprintf(temporary,"%sUserSetting",pj_editor_Dir);
8
9    HANDLE hFind;
10    WIN32_FIND_DATA wfd;
11    hFind=FindFirstFile(temporary,&wfd);
12    if(hFind==INVALID_HANDLE_VALUE){
13        //UserSettingディレクトリを作成
14        if(!CreateDirectory(temporary,NULL)){
15            MessageBox(hOwner,"UserSettingディレクトリの作成に失敗",APPLICATION_NAME,MB_OK|MB_ICONEXCLAMATION);
16            return;
17        }
18    }
19}
20
21char *ReadBuffer( const std::string &path ){
22    extern HANDLE hHeap;
23    int i;
24    DWORD dw;
25    char *buffer,temporary[MAX_PATH];
26    HANDLE hFile;
27
28    hFile=CreateFile(path.c_str(),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
29    if(hFile==INVALID_HANDLE_VALUE){
30        //"\"%s\" ファイルの読み込みに失敗しました。"
31        sprintf(temporary,STRING_ERROR_CANT_FILEOPEN,path.c_str());
32        MessageBox(hOwner,temporary,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
33
34        return 0;
35    }
36    i=GetFileSize(hFile,0);
37    buffer=(char *)HeapAlloc(hHeap,0,i+1);
38    ReadFile(hFile,buffer,i,&dw,0);
39    buffer[dw]=0;
40    CloseHandle(hFile);
41    return buffer;
42}
43char *ReadBuffer_NonErrMsg( const std::string &path ){
44    extern HANDLE hHeap;
45    int i;
46    DWORD dw;
47    char *buffer;
48    HANDLE hFile;
49
50    hFile=CreateFile(path.c_str(),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
51    if(hFile==INVALID_HANDLE_VALUE) return 0;
52    i=GetFileSize(hFile,0);
53    buffer=(char *)HeapAlloc(hHeap,0,i+1);
54    ReadFile(hFile,buffer,i,&dw,0);
55    buffer[dw]=0;
56    CloseHandle(hFile);
57    return buffer;
58}
59_int8 WriteBuffer(const std::string &path,char *buffer,int length, bool isEnableError){
60    HANDLE hFile;
61    DWORD dw;
62    hFile=CreateFile(path.c_str(),GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
63    if(hFile==INVALID_HANDLE_VALUE){
64        char temporary[MAX_PATH];
65
66        if( isEnableError ){
67            //"\"%s\" ファイルへの書き込みに失敗しました。"
68            sprintf(temporary,STRING_ERROR_CANT_FILESAVE,path);
69            MessageBox(hOwner,temporary,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
70        }
71        return 0;
72    }
73    if(length) WriteFile(hFile,buffer,length,&dw,NULL);
74    CloseHandle(hFile);
75    return 1;
76}
77_int8 WriteBuffer_NonErrMsg(const std::string &path,char *buffer,int length){
78    return WriteBuffer( path, buffer, length, false );
79}
80void GetRelationalPath(char *path,char *dir){
81    //相対パスを取得
82    int i,i2,i3,i4,i5;
83    char temporary[MAX_PATH],temp2[MAX_PATH],temp3[MAX_PATH],temp4[MAX_PATH];
84
85    //ドライブ名をチェック
86    _splitpath(path,temporary,0,0,0);
87    _splitpath(dir,temp2,0,0,0);
88    if(lstrcmpi(temporary,temp2)!=0) return;
89
90    _splitpath(path,0,temporary,0,0);
91    _splitpath(dir,0,temp2,0,0);
92    i=1;i2=1;
93    while(1){
94        i4=i;
95        if(temporary[i-1]=='\\'&&temporary[i]){ //path側
96            for(i3=0;;i++,i3++){
97                if(temporary[i]=='\\'){
98                    temp3[i3]=0;
99                    i++;
100                    break;
101                }
102                temp3[i3]=temporary[i];
103            }
104        }
105        else temp3[0]=0;
106
107        i5=i2;
108        if(temp2[i2-1]=='\\'&&temp2[i2]){       //dir側
109            for(i3=0;;i2++,i3++){
110                if(temp2[i2]=='\\'){
111                    temp4[i3]=0;
112                    i2++;
113                    break;
114                }
115                temp4[i3]=temp2[i2];
116            }
117        }
118        else temp4[0]=0;
119
120        if(temp3[0]=='\0'&&temp4[0]=='\0') break;
121
122        if(lstrcmpi(temp3,temp4)!=0){
123            for(i3=0;;i5++){
124                if(temp2[i5]=='\0') break;
125                if(temp2[i5]=='\\') i3++;
126            }
127            temp3[0]=0;
128            for(i2=0;i2<i3;i2++) lstrcat(temp3,"..\\");
129            lstrcat(temp3,temporary+i4);
130            break;
131        }
132    }
133    _splitpath(path,0,0,temporary,temp2);
134    lstrcat(temp3,temporary);
135    lstrcat(temp3,temp2);
136    lstrcpy(path,temp3);
137}
138void GetFullPath(char *path,const char *dir){
139    int i,i2,i3,i4;
140    char temporary[MAX_PATH];
141
142    if(strstr(path,":")||strstr(path,"\\\\")) return;
143
144    i=0;i2=0;
145    while(1){
146        if(path[i]=='.'&&path[i+1]=='\\') i+=2;
147        if(path[i]=='.'&&path[i+1]=='.'&&path[i+2]=='\\'){
148            i2++;
149            i+=3;
150        }
151        else break;
152    }
153
154    i3=lstrlen(dir);i4=0;
155    while(i4<i2){
156        for(i3--;;i3--){
157            if(dir[i3-1]=='\\'){
158                i4++;
159                break;
160            }
161        }
162    }
163    memcpy(temporary,dir,i3);
164    temporary[i3]=0;
165    lstrcat(temporary,path+i);
166    lstrcpy(path,temporary);
167}
168
169void RemoveDirectoryStrong(const char *dirPath){
170    char tempDirPath[MAX_PATH];
171    lstrcpy( tempDirPath, dirPath );
172
173    if( tempDirPath[lstrlen(tempDirPath)-1] == '\\' ){
174         tempDirPath[lstrlen(tempDirPath)-1] = 0;
175    }
176
177    HANDLE hFind;
178    WIN32_FIND_DATA wfd;
179    char temporary[MAX_PATH];
180    sprintf(temporary,"%s\\*",tempDirPath);
181
182    hFind=FindFirstFile(temporary,&wfd);
183    if(hFind!=INVALID_HANDLE_VALUE){
184        do{
185            if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
186                if(!(lstrcmp(wfd.cFileName,".")==0||lstrcmp(wfd.cFileName,"..")==0)){
187                    //ディレクトリのとき
188                    sprintf(temporary,"%s\\%s\\",tempDirPath,wfd.cFileName);
189                    RemoveDirectoryStrong(temporary);
190                }
191            }
192            else{
193                //ファイルのとき
194                sprintf(temporary,"%s\\%s",tempDirPath,wfd.cFileName);
195
196                DeleteFile(temporary);
197            }
198        }while(FindNextFile(hFind,&wfd));
199
200        FindClose( hFind );
201    }
202
203    if( !RemoveDirectory(tempDirPath) ){
204        OutputDebugString( GetLastErrorString().c_str() );
205        OutputDebugString( "\r\n" );
206        OutputDebugString( "一時ディレクトリの削除に失敗\r\n" );
207    }
208}
209
210BOOL GetFilePathDialog(HWND hwnd,char *filename,LPSTR Filter,LPSTR Title,_int8 IsOpen){
211    OPENFILENAME ofstr;
212    filename[0]=0;
213    ofstr.lStructSize=sizeof(OPENFILENAME);
214    ofstr.hwndOwner=hwnd;
215    ofstr.hInstance=0;
216    ofstr.lpstrFilter=Filter;
217    ofstr.lpstrCustomFilter=NULL;
218    ofstr.nMaxCustFilter=0;
219    ofstr.nFilterIndex=1;
220    ofstr.lpstrFile=filename;
221    ofstr.nMaxFile=MAX_PATH;
222    ofstr.lpstrFileTitle=NULL;
223    ofstr.nMaxFileTitle=0;
224    ofstr.lpstrInitialDir=pobj_nv->DefSaveDir;
225    ofstr.lpstrTitle=Title;
226    ofstr.Flags=OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST;
227    ofstr.nFileOffset=0;
228    ofstr.nFileExtension=0;
229    ofstr.lpstrDefExt="*";
230    ofstr.lCustData=NULL;
231    ofstr.lpfnHook=NULL;
232    ofstr.lpTemplateName=NULL;
233    if(IsOpen){
234        if(!GetOpenFileName(&ofstr)) return FALSE;
235    }
236    else{
237        if(!GetSaveFileName(&ofstr)) return FALSE;
238    }
239
240    //次回の初期ディレクトリをセット
241    char temporary[MAX_PATH];
242    _splitpath(filename,pobj_nv->DefSaveDir,temporary,NULL,NULL);
243    lstrcat(pobj_nv->DefSaveDir,temporary);
244
245    return TRUE;
246}
247BOOL GetFolder(HWND hWnd,char *folder,char *OpenFolderTitle){
248    BROWSEINFO BrowseInfo;
249    LPITEMIDLIST pidlBrowse;
250    LPMALLOC g_pMalloc;
251    char temporary[MAX_PATH];
252
253    BrowseInfo.hwndOwner=hWnd;
254    BrowseInfo.pszDisplayName=temporary;
255    BrowseInfo.pidlRoot=NULL;
256    BrowseInfo.lpszTitle=OpenFolderTitle;
257    BrowseInfo.ulFlags=BIF_RETURNONLYFSDIRS;
258    BrowseInfo.lpfn=NULL;
259    BrowseInfo.lParam=(LPARAM)0;
260    BrowseInfo.iImage=0;
261    pidlBrowse=SHBrowseForFolder(&BrowseInfo);
262    if(pidlBrowse){
263        if(SHGetMalloc(&g_pMalloc)!=0) return 0;
264        SHGetPathFromIDList(pidlBrowse,folder);
265        g_pMalloc->Free(pidlBrowse);
266        g_pMalloc->Release();
267        return 1;
268    }
269    return 0;
270}
271
272int GetFileExtension(char *path){
273    char temporary[MAX_PATH];
274    _splitpath(path,0,0,0,temporary);
275
276    if(lstrcmpi(temporary,".bas")==0||
277        lstrcmpi(temporary,".ab")==0||
278        lstrcmpi(temporary,".abp")==0) return FT_BASICPROGRAM;
279    if(lstrcmpi(temporary,".sbp")==0) return FT_SUBPROGRAM;
280    if(lstrcmpi(temporary,".txt")==0) return FT_TEXT;
281    if(lstrcmpi(temporary,".pj")==0) return FT_PROJECT;
282    if(lstrcmpi(temporary,".ico")==0) return FT_ICON;
283
284    if(lstrcmpi(temporary,".html")==0||
285        lstrcmpi(temporary,".htm")==0||
286        lstrcmpi(temporary,".tpl")==0||
287        lstrcmpi(temporary,".php")==0)
288        return FT_HTML;
289
290    return FT_OTHER;
291}
292HWND OpenFileWithExtension( const std::string &filePath )
293{
294    int i;
295    _int8 DocumentType;
296
297    // TODO:
298    char *OpenFileName = const_cast<char *>(filePath.c_str());
299
300    i=GetFileExtension(OpenFileName);
301
302#ifndef THETEXT
303    if(i==FT_PROJECT){
304        //「最近使ったプロジェクト」に追加
305        pobj_nv->pobj_ProjectHistory->insert(OpenFileName);
306
307        projectInfo.Load(OpenFileName);
308        return 0;
309    }
310#endif
311
312    //「最近使ったファイル」に追加
313    pobj_nv->pobj_History->insert(OpenFileName);
314
315    if(i==FT_ICON){
316        NewIconEditWindow(OpenFileName);
317        return 0;
318    }
319    else if(i==FT_BASICPROGRAM||i==FT_SUBPROGRAM){
320        DocumentType=WNDTYPE_BASIC;
321
322#ifdef THETEXT
323        DocumentType=WNDTYPE_TEXT;
324#endif
325    }
326    else if(i==FT_HTML) DocumentType=WNDTYPE_HTML;
327    else DocumentType=WNDTYPE_TEXT;
328
329    COLORREF TabColor;
330    TabColor=pobj_nv->pobj_ExtLink->GetTabColorFromFilePath(OpenFileName);
331
332    return NewTextEditWindow(OpenFileName,DocumentType,TabColor);
333}
334BOOL SaveDocument(HWND hChild,char *SaveFileName){  //ウィンドウからバッファを読み取り、ファイルに保存
335    extern LPSTR IconFileFilter;
336    extern HWND hClient,hDocCombo;
337    extern MDIINFO MdiInfo[MAX_WNDNUM];
338    int WndNum,i2;
339    char temporary[MAX_PATH],str[MAX_PATH],str2[32];
340    HANDLE fh;
341    DWORD dummy;
342
343    WndNum=GetWndNum(hChild);
344
345    char szOldTitle[MAX_PATH];
346    lstrcpy(szOldTitle,MdiInfo[WndNum].title);
347
348    if(MdiInfo[WndNum].DocType==WNDTYPE_RAD||MdiInfo[WndNum].DocType==WNDTYPE_MENU){
349        ////////////////////////////////////
350        // RADツール及びメニューエディタ
351        ////////////////////////////////////
352
353        if(projectInfo.ModifyOfMaterial){
354            sprintf(temporary,"%s%s.wnd",projectInfo.GetWorkDir().GetPath().c_str(),projectInfo.GetName().c_str());
355            SaveWindowFile( temporary, projectInfo.windowInfos );
356
357            //.wbpファイルを生成
358            SaveWindowProgram();
359        }
360    }
361    else if(IS_DOCUMENT_TEXT(MdiInfo[WndNum].DocType)){
362        //////////////////////////
363        // テキストドキュメント
364        //////////////////////////
365
366        if(SaveFileName){
367            lstrcpy(temporary,SaveFileName);
368            if((fh=CreateFile(temporary,GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL))==INVALID_HANDLE_VALUE){
369                sprintf(str,STRING_FILE_OVERWRIDE,temporary);
370                if(MessageBox(hOwner,str,APPLICATION_NAME,MB_YESNO|MB_ICONINFORMATION)==IDNO){
371                    CloseHandle(fh);
372                    return 0;
373                }
374            }
375            CloseHandle(fh);
376
377            //ドキュメント セレクト コンボボックスから消去
378            i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(long)MdiInfo[WndNum].title);
379            SendMessage(hDocCombo,CB_DELETESTRING,i2,0);
380
381            //新しいパスをセット
382            GlobalFree(MdiInfo[WndNum].path);
383            MdiInfo[WndNum].path=(char *)GlobalAlloc(GMEM_FIXED,lstrlen(temporary)+1);
384            lstrcpy(MdiInfo[WndNum].path,temporary);
385
386            //ドキュメント セレクト コンボボックスに挿入
387            _splitpath(temporary,NULL,NULL,str,str2);
388            lstrcat(str,str2);
389            GlobalFree(MdiInfo[WndNum].title);
390            MdiInfo[WndNum].title=(char *)GlobalAlloc(GMEM_FIXED,lstrlen(str)+1);
391            lstrcpy(MdiInfo[WndNum].title,str);
392            SendMessage(hDocCombo,CB_ADDSTRING,0,(long)MdiInfo[WndNum].title);
393            i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(long)MdiInfo[WndNum].title);
394            SendMessage(hDocCombo,CB_SETCURSEL,i2,0);
395
396            //MDIウィンドウのタイトルを再設定
397            SetWindowText(hChild,MdiInfo[WndNum].title);
398        }
399        else{
400            if(MdiInfo[WndNum].path[0]=='\0'){
401                //"保存先のファイルを指定してください"
402get_file_path:
403
404                LPSTR ff;
405
406                extern LPSTR DefFileFilter;
407                extern LPSTR HtmlFileFilter;
408                extern LPSTR TextFileFilter;
409                if(MdiInfo[WndNum].DocType==WNDTYPE_BASIC)
410                    ff=DefFileFilter;
411                else if(MdiInfo[WndNum].DocType==WNDTYPE_HTML)
412                    ff=HtmlFileFilter;
413                else if(MdiInfo[WndNum].DocType==WNDTYPE_TEXT)
414                    ff=TextFileFilter;
415
416                if(!GetFilePathDialog(hOwner,temporary,ff,STRING_FILESAVETITLE_DEFAULT,FALSE)) return 0;
417                SaveDocument(hChild,temporary);
418                return 1;
419            }
420            lstrcpy(temporary,MdiInfo[WndNum].path);
421        }
422
423        if(!IsExistFile(temporary)){
424            //保存先ファイルが存在しないとき
425            char temp2[MAX_PATH];
426
427            //初期ディレクトリをセット
428            _splitpath(temporary,pobj_nv->DefSaveDir,temp2,NULL,NULL);
429            lstrcat(pobj_nv->DefSaveDir,temp2);
430
431            goto get_file_path;
432        }
433
434        //文字コードを復元
435        char *pBuf;
436        pBuf=nkf.RestoreBuffer(MdiInfo[WndNum].pMdiTextEdit->buffer,MdiInfo[WndNum].pMdiTextEdit->iCharCode);
437
438        //改行コードを復元
439        if(MdiInfo[WndNum].pMdiTextEdit->iLfCode==LFCODE_LF) nkf.ToLF(pBuf);
440        else if(MdiInfo[WndNum].pMdiTextEdit->iLfCode==LFCODE_CR) nkf.ToCR(pBuf);
441
442
443        ////////////////////////
444        // 保存
445        ////////////////////////
446
447        fh=CreateFile(temporary,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
448        if(fh==INVALID_HANDLE_VALUE){
449            sprintf(str,STRING_ERROR_CANT_FILESAVE,temporary);
450            MessageBox(hOwner,str,STRING_ERROR,MB_OK|MB_ICONSTOP);
451            return 0;
452        }
453        WriteFile(fh,pBuf,lstrlen(pBuf),&dummy,NULL);
454        CloseHandle(fh);
455
456
457        HeapDefaultFree(pBuf);
458
459        //変更フラグをオフにする
460        MdiInfo[WndNum].pMdiTextEdit->UnModify();
461    }
462    else if(MdiInfo[WndNum].DocType==WNDTYPE_ICONEDIT){
463        ///////////////////
464        // ICON
465        ///////////////////
466
467        if(SaveFileName){
468            lstrcpy(temporary,SaveFileName);
469            if((fh=CreateFile(temporary,GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL))==INVALID_HANDLE_VALUE){
470                sprintf(str,STRING_FILE_OVERWRIDE,temporary);
471                if(MessageBox(hOwner,str,APPLICATION_NAME,MB_YESNO|MB_ICONINFORMATION)==IDNO){
472                    CloseHandle(fh);
473                    return 0;
474                }
475            }
476            CloseHandle(fh);
477            GlobalFree(MdiInfo[WndNum].path);
478            MdiInfo[WndNum].path=(char *)GlobalAlloc(GMEM_FIXED,lstrlen(temporary)+1);
479            lstrcpy(MdiInfo[WndNum].path,temporary);
480            i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(long)MdiInfo[WndNum].title);
481            SendMessage(hDocCombo,CB_DELETESTRING,i2,0);
482            _splitpath(temporary,NULL,NULL,str,str2);
483            lstrcat(str,str2);
484            lstrcpy(MdiInfo[WndNum].title,str);
485            SendMessage(hDocCombo,CB_ADDSTRING,0,(long)MdiInfo[WndNum].title);
486            i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(long)MdiInfo[WndNum].title);
487            SendMessage(hDocCombo,CB_SETCURSEL,i2,0);
488            SetWindowText(hChild,MdiInfo[WndNum].title);
489        }
490        else{
491            if(MdiInfo[WndNum].path[0]=='\0'){
492                //"保存先のファイルを指定してください"
493                if(!GetFilePathDialog(hOwner,temporary,IconFileFilter,STRING_FILESAVETITLE_DEFAULT,FALSE)) return 0;
494                SaveDocument(hChild,temporary);
495                return 1;
496            }
497            lstrcpy(temporary,MdiInfo[WndNum].path);
498        }
499        SaveIconFile(temporary,hChild);
500
501        MdiInfo[WndNum].MdiIconEditInfo->bModify=0;
502    }
503
504
505    //タブコントロールを再設定
506    if(pobj_nv->bSaveTabToHead){
507        COLORREF color;
508        color=pobj_MainTab->GetItemColor(szOldTitle);
509        pobj_MainTab->DeleteItem( szOldTitle, false );
510        pobj_MainTab->InsertItem( MdiInfo[WndNum].title, false, color );
511    }
512    else{
513        pobj_MainTab->RenameItem( szOldTitle, MdiInfo[WndNum].title );
514    }
515
516    //「最近使ったファイル」を更新
517    pobj_nv->pobj_History->insert(MdiInfo[WndNum].path);
518
519    return 1;
520}
521BOOL ShortPathToLongPath(char ShortPath[MAX_PATH],char *LongPath){
522    HANDLE hFind;
523    WIN32_FIND_DATA wfd;
524    int i;
525    char dummy[MAX_PATH];
526    for(i=0;i<MAX_PATH;i++){
527        LongPath[i]=ShortPath[i];
528        if((ShortPath[i-1]==':'&&ShortPath[i]=='\\')||(ShortPath[i-1]=='\\'&&ShortPath[i]=='\\')){
529            LongPath[i+1]=0;
530            break;
531        }
532    }
533    if(ShortPath[i-1]=='\\'&&ShortPath[i]=='\\'){
534        for(i++;i<MAX_PATH;i++){
535            if(IsDBCSLeadByte(ShortPath[i])){
536                i++;
537                continue;
538            }
539            LongPath[i]=ShortPath[i];
540            if(ShortPath[i]=='\\'){
541                LongPath[i+1]=0;
542                break;
543            }
544        }
545        for(i++;i<MAX_PATH;i++){
546            if(IsDBCSLeadByte(ShortPath[i])){
547                i++;
548                continue;
549            }
550            LongPath[i]=ShortPath[i];
551            if(ShortPath[i]=='\\'){
552                LongPath[i+1]=0;
553                break;
554            }
555        }
556    }
557    for(i++;i<MAX_PATH;i++){
558        if(IsDBCSLeadByte(ShortPath[i])){
559            i++;
560            continue;
561        }
562        if(ShortPath[i]=='\\'||ShortPath[i]=='\0'){
563            strncpy(dummy,ShortPath,i);
564            dummy[i]=0;
565            if((hFind=FindFirstFile(dummy,&wfd))!=INVALID_HANDLE_VALUE) FindClose(hFind);
566            lstrcat(LongPath,wfd.cFileName);
567
568            if(ShortPath[i]=='\0') break;
569            lstrcat(LongPath,"\\");
570
571            if(ShortPath[i]=='\\'&&ShortPath[i+1]=='\0'){
572                break;
573            }
574        }
575    }
576    return 1;
577}
578
579bool IsExistFile( const char *FilePath ){
580    WIN32_FIND_DATA wfd;
581    HANDLE hFind;
582
583    hFind = FindFirstFile(FilePath,&wfd);
584    if( hFind == INVALID_HANDLE_VALUE ){
585        return false;
586    }
587    FindClose( hFind );
588
589    return true;
590}
591
592bool IsExistDirectory( const char *DirPath ){
593    WIN32_FIND_DATA wfd;
594    HANDLE hFind;
595
596    hFind = FindFirstFile(DirPath,&wfd);
597    if( hFind == INVALID_HANDLE_VALUE ){
598        //存在しない
599        return false;
600    }
601    FindClose( hFind );
602
603    if( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ){
604        //ディレクトリの場合
605        return true;
606    }
607
608    //存在しない
609    return false;
610}
Note: See TracBrowser for help on using the repository browser.