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