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