[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 |
|
---|
[705] | 30 | ATL::CHandle hFile(CreateFile(path.c_str(),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL));
|
---|
[3] | 31 | if(hFile==INVALID_HANDLE_VALUE){
|
---|
[705] | 32 | hFile.Detach();
|
---|
[3] | 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 | return buffer;
|
---|
| 44 | }
|
---|
[475] | 45 | char *ReadBuffer_NonErrMsg( const std::string &path ){
|
---|
[3] | 46 | extern HANDLE hHeap;
|
---|
| 47 | DWORD dw;
|
---|
| 48 |
|
---|
[705] | 49 | ATL::CHandle hFile(CreateFile(path.c_str(),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL));
|
---|
| 50 | if(hFile==INVALID_HANDLE_VALUE){
|
---|
| 51 | hFile.Detach();
|
---|
| 52 | return 0;
|
---|
| 53 | }
|
---|
| 54 | int i=GetFileSize(hFile,0);
|
---|
| 55 | char *buffer=(char *)HeapAlloc(hHeap,0,i+1);
|
---|
[3] | 56 | ReadFile(hFile,buffer,i,&dw,0);
|
---|
| 57 | buffer[dw]=0;
|
---|
| 58 | return buffer;
|
---|
| 59 | }
|
---|
[625] | 60 | _int8 WriteBuffer(const std::string &path,const char *buffer,int length, bool isEnableError)
|
---|
| 61 | {
|
---|
[3] | 62 | DWORD dw;
|
---|
[705] | 63 | ATL::CHandle hFile(CreateFile(path.c_str(),GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL));
|
---|
[3] | 64 | if(hFile==INVALID_HANDLE_VALUE){
|
---|
[705] | 65 | hFile.Detach();
|
---|
| 66 |
|
---|
[3] | 67 | char temporary[MAX_PATH];
|
---|
[99] | 68 | if( isEnableError ){
|
---|
| 69 | //"\"%s\" ファイルへの書き込みに失敗しました。"
|
---|
| 70 | sprintf(temporary,STRING_ERROR_CANT_FILESAVE,path);
|
---|
| 71 | MessageBox(hOwner,temporary,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
|
---|
| 72 | }
|
---|
[3] | 73 | return 0;
|
---|
| 74 | }
|
---|
| 75 | if(length) WriteFile(hFile,buffer,length,&dw,NULL);
|
---|
| 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 |
|
---|
[651] | 273 | int GetFileExtension( const char *path )
|
---|
| 274 | {
|
---|
[3] | 275 | char temporary[MAX_PATH];
|
---|
| 276 | _splitpath(path,0,0,0,temporary);
|
---|
| 277 |
|
---|
| 278 | if(lstrcmpi(temporary,".bas")==0||
|
---|
| 279 | lstrcmpi(temporary,".ab")==0||
|
---|
| 280 | lstrcmpi(temporary,".abp")==0) return FT_BASICPROGRAM;
|
---|
| 281 | if(lstrcmpi(temporary,".sbp")==0) return FT_SUBPROGRAM;
|
---|
| 282 | if(lstrcmpi(temporary,".txt")==0) return FT_TEXT;
|
---|
| 283 | if(lstrcmpi(temporary,".pj")==0) return FT_PROJECT;
|
---|
| 284 | if(lstrcmpi(temporary,".ico")==0) return FT_ICON;
|
---|
| 285 |
|
---|
| 286 | if(lstrcmpi(temporary,".html")==0||
|
---|
| 287 | lstrcmpi(temporary,".htm")==0||
|
---|
| 288 | lstrcmpi(temporary,".tpl")==0||
|
---|
| 289 | lstrcmpi(temporary,".php")==0)
|
---|
| 290 | return FT_HTML;
|
---|
| 291 |
|
---|
| 292 | return FT_OTHER;
|
---|
| 293 | }
|
---|
[620] | 294 | HWND OpenFileWithExtension( const std::string &filePath )
|
---|
| 295 | {
|
---|
[3] | 296 | int i;
|
---|
| 297 | _int8 DocumentType;
|
---|
| 298 |
|
---|
[620] | 299 | // TODO:
|
---|
[697] | 300 | char const *OpenFileName = filePath.c_str();
|
---|
[620] | 301 |
|
---|
[3] | 302 | i=GetFileExtension(OpenFileName);
|
---|
| 303 |
|
---|
| 304 | #ifndef THETEXT
|
---|
| 305 | if(i==FT_PROJECT){
|
---|
| 306 | //「最近使ったプロジェクト」に追加
|
---|
| 307 | pobj_nv->pobj_ProjectHistory->insert(OpenFileName);
|
---|
| 308 |
|
---|
[621] | 309 | projectInfo.Load(OpenFileName);
|
---|
[3] | 310 | return 0;
|
---|
| 311 | }
|
---|
| 312 | #endif
|
---|
| 313 |
|
---|
| 314 | //「最近使ったファイル」に追加
|
---|
| 315 | pobj_nv->pobj_History->insert(OpenFileName);
|
---|
| 316 |
|
---|
| 317 | if(i==FT_ICON){
|
---|
| 318 | NewIconEditWindow(OpenFileName);
|
---|
| 319 | return 0;
|
---|
| 320 | }
|
---|
| 321 | else if(i==FT_BASICPROGRAM||i==FT_SUBPROGRAM){
|
---|
| 322 | DocumentType=WNDTYPE_BASIC;
|
---|
| 323 |
|
---|
| 324 | #ifdef THETEXT
|
---|
| 325 | DocumentType=WNDTYPE_TEXT;
|
---|
| 326 | #endif
|
---|
| 327 | }
|
---|
| 328 | else if(i==FT_HTML) DocumentType=WNDTYPE_HTML;
|
---|
| 329 | else DocumentType=WNDTYPE_TEXT;
|
---|
| 330 |
|
---|
| 331 | COLORREF TabColor;
|
---|
[625] | 332 | TabColor=pobj_nv->pobj_ExtLink->GetTabColorFromFilePath( filePath );
|
---|
[3] | 333 |
|
---|
| 334 | return NewTextEditWindow(OpenFileName,DocumentType,TabColor);
|
---|
| 335 | }
|
---|
[700] | 336 |
|
---|
| 337 | BOOL GetFileInformationByHandleWrap(HANDLE hFile, BY_HANDLE_FILE_INFORMATION& fi){
|
---|
| 338 | typedef BOOL WINAPI GFIBH(HANDLE, LPBY_HANDLE_FILE_INFORMATION);
|
---|
| 339 | GFIBH *const pgfibh = reinterpret_cast<GFIBH*>(
|
---|
| 340 | GetProcAddress(GetModuleHandle("kernel32"), "GetFileInformationByHandle"));
|
---|
| 341 | if(pgfibh){
|
---|
| 342 | return pgfibh(hFile, &fi);
|
---|
| 343 | }
|
---|
| 344 | else{
|
---|
| 345 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
---|
| 346 | return FALSE;
|
---|
| 347 | }
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | //重複チェック用のデータを設定
|
---|
| 351 | void SetFileIdentity(FILEIDENTITY &fi, BY_HANDLE_FILE_INFORMATION const &bhfi){
|
---|
| 352 | fi.VolumeSerialNumber = bhfi.dwVolumeSerialNumber;
|
---|
| 353 | fi.FileIndexHigh = bhfi.nFileIndexHigh;
|
---|
| 354 | fi.FileIndexLow = bhfi.nFileIndexLow;
|
---|
| 355 | }
|
---|
| 356 |
|
---|
| 357 | void SetFileIdentityFromFile(MDIINFO &mi, HANDLE hFile){
|
---|
| 358 | BY_HANDLE_FILE_INFORMATION fi;
|
---|
| 359 | if(GetFileInformationByHandleWrap(hFile, fi)){
|
---|
| 360 | SetFileIdentity(mi.FileIdentity, fi);
|
---|
| 361 | }
|
---|
| 362 | }
|
---|
| 363 |
|
---|
[3] | 364 | BOOL SaveDocument(HWND hChild,char *SaveFileName){ //ウィンドウからバッファを読み取り、ファイルに保存
|
---|
[700] | 365 | //SaveFileNameがNULLのときは上書き保存を試みる。
|
---|
[3] | 366 | extern LPSTR IconFileFilter;
|
---|
| 367 | extern HWND hClient,hDocCombo;
|
---|
| 368 | int WndNum,i2;
|
---|
| 369 | char temporary[MAX_PATH],str[MAX_PATH],str2[32];
|
---|
| 370 | DWORD dummy;
|
---|
| 371 |
|
---|
| 372 | WndNum=GetWndNum(hChild);
|
---|
| 373 |
|
---|
[700] | 374 | std::string oldTitle = MdiInfo[WndNum]->title;
|
---|
[3] | 375 |
|
---|
[629] | 376 | if(MdiInfo[WndNum]->DocType==WNDTYPE_RAD||MdiInfo[WndNum]->DocType==WNDTYPE_MENU){
|
---|
[3] | 377 | ////////////////////////////////////
|
---|
| 378 | // RADツール及びメニューエディタ
|
---|
| 379 | ////////////////////////////////////
|
---|
| 380 |
|
---|
[618] | 381 | if(projectInfo.ModifyOfMaterial){
|
---|
[700] | 382 | std::string const& workDir = projectInfo.GetWorkDir().GetPath();
|
---|
| 383 | std::string const& projName = projectInfo.GetName();
|
---|
| 384 | std::string t;
|
---|
| 385 | t.reserve( workDir.size() + projName.size() + 4 );
|
---|
| 386 | t += workDir;
|
---|
| 387 | t += projName;
|
---|
| 388 | t += ".wnd";
|
---|
| 389 | SaveWindowFile( t.c_str(), projectInfo.windowInfos );
|
---|
[3] | 390 |
|
---|
| 391 | //.wbpファイルを生成
|
---|
| 392 | SaveWindowProgram();
|
---|
| 393 | }
|
---|
| 394 | }
|
---|
[629] | 395 | else if(IS_DOCUMENT_TEXT(MdiInfo[WndNum]->DocType)){
|
---|
[3] | 396 | //////////////////////////
|
---|
| 397 | // テキストドキュメント
|
---|
| 398 | //////////////////////////
|
---|
| 399 |
|
---|
| 400 | if(SaveFileName){
|
---|
| 401 | lstrcpy(temporary,SaveFileName);
|
---|
[705] | 402 | {
|
---|
| 403 | ATL::CHandle fh(CreateFile(temporary,GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL));
|
---|
| 404 | if(fh==INVALID_HANDLE_VALUE){
|
---|
| 405 | fh.Detach();
|
---|
| 406 | sprintf(str,STRING_FILE_OVERWRIDE,temporary);
|
---|
| 407 | if(MessageBox(hOwner,str,APPLICATION_NAME,MB_YESNO|MB_ICONINFORMATION)==IDNO){
|
---|
| 408 | return 0;
|
---|
| 409 | }
|
---|
[3] | 410 | }
|
---|
| 411 | }
|
---|
| 412 |
|
---|
| 413 | //ドキュメント セレクト コンボボックスから消去
|
---|
[700] | 414 | i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(LONG_PTR)MdiInfo[WndNum]->title.c_str());
|
---|
[3] | 415 | SendMessage(hDocCombo,CB_DELETESTRING,i2,0);
|
---|
| 416 |
|
---|
| 417 | //新しいパスをセット
|
---|
[629] | 418 | MdiInfo[WndNum]->path = temporary;
|
---|
[3] | 419 |
|
---|
| 420 | //ドキュメント セレクト コンボボックスに挿入
|
---|
| 421 | _splitpath(temporary,NULL,NULL,str,str2);
|
---|
| 422 | lstrcat(str,str2);
|
---|
[629] | 423 | MdiInfo[WndNum]->title = str;
|
---|
[700] | 424 | SendMessage(hDocCombo,CB_ADDSTRING,0,(LONG_PTR)MdiInfo[WndNum]->title.c_str());
|
---|
| 425 | i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(LONG_PTR)MdiInfo[WndNum]->title.c_str());
|
---|
[3] | 426 | SendMessage(hDocCombo,CB_SETCURSEL,i2,0);
|
---|
| 427 |
|
---|
| 428 | //MDIウィンドウのタイトルを再設定
|
---|
[629] | 429 | SetWindowText(hChild,MdiInfo[WndNum]->title.c_str());
|
---|
[3] | 430 | }
|
---|
| 431 | else{
|
---|
[629] | 432 | if(MdiInfo[WndNum]->path.empty()){
|
---|
[3] | 433 | //"保存先のファイルを指定してください"
|
---|
| 434 | get_file_path:
|
---|
| 435 |
|
---|
| 436 | LPSTR ff;
|
---|
| 437 |
|
---|
| 438 | extern LPSTR DefFileFilter;
|
---|
| 439 | extern LPSTR HtmlFileFilter;
|
---|
| 440 | extern LPSTR TextFileFilter;
|
---|
[629] | 441 | if(MdiInfo[WndNum]->DocType==WNDTYPE_BASIC)
|
---|
[3] | 442 | ff=DefFileFilter;
|
---|
[629] | 443 | else if(MdiInfo[WndNum]->DocType==WNDTYPE_HTML)
|
---|
[3] | 444 | ff=HtmlFileFilter;
|
---|
[629] | 445 | else if(MdiInfo[WndNum]->DocType==WNDTYPE_TEXT)
|
---|
[3] | 446 | ff=TextFileFilter;
|
---|
| 447 |
|
---|
| 448 | if(!GetFilePathDialog(hOwner,temporary,ff,STRING_FILESAVETITLE_DEFAULT,FALSE)) return 0;
|
---|
| 449 | SaveDocument(hChild,temporary);
|
---|
| 450 | return 1;
|
---|
| 451 | }
|
---|
[629] | 452 | lstrcpy(temporary,MdiInfo[WndNum]->path.c_str());
|
---|
[3] | 453 | }
|
---|
| 454 |
|
---|
[22] | 455 | if(!IsExistFile(temporary)){
|
---|
[3] | 456 | //保存先ファイルが存在しないとき
|
---|
| 457 | char temp2[MAX_PATH];
|
---|
| 458 |
|
---|
| 459 | //初期ディレクトリをセット
|
---|
| 460 | _splitpath(temporary,pobj_nv->DefSaveDir,temp2,NULL,NULL);
|
---|
| 461 | lstrcat(pobj_nv->DefSaveDir,temp2);
|
---|
| 462 |
|
---|
| 463 | goto get_file_path;
|
---|
| 464 | }
|
---|
| 465 |
|
---|
| 466 | //文字コードを復元
|
---|
| 467 | char *pBuf;
|
---|
[629] | 468 | pBuf=nkf.RestoreBuffer(MdiInfo[WndNum]->pMdiTextEdit->buffer,MdiInfo[WndNum]->pMdiTextEdit->iCharCode);
|
---|
[3] | 469 |
|
---|
| 470 | //改行コードを復元
|
---|
[629] | 471 | if(MdiInfo[WndNum]->pMdiTextEdit->iLfCode==LFCODE_LF) nkf.ToLF(pBuf);
|
---|
| 472 | else if(MdiInfo[WndNum]->pMdiTextEdit->iLfCode==LFCODE_CR) nkf.ToCR(pBuf);
|
---|
[3] | 473 |
|
---|
| 474 |
|
---|
| 475 | ////////////////////////
|
---|
| 476 | // 保存
|
---|
| 477 | ////////////////////////
|
---|
| 478 |
|
---|
[705] | 479 | {
|
---|
| 480 | ATL::CHandle fh(CreateFile(temporary,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL));
|
---|
| 481 | if(fh==INVALID_HANDLE_VALUE){
|
---|
| 482 | fh.Detach();
|
---|
| 483 | sprintf(str,STRING_ERROR_CANT_FILESAVE,temporary);
|
---|
| 484 | MessageBox(hOwner,str,STRING_ERROR,MB_OK|MB_ICONSTOP);
|
---|
| 485 | return 0;
|
---|
| 486 | }
|
---|
| 487 | WriteFile(fh,pBuf,strlen(pBuf),&dummy,NULL);
|
---|
| 488 | SetFileIdentityFromFile(*MdiInfo[WndNum], fh);
|
---|
[3] | 489 | }
|
---|
| 490 |
|
---|
| 491 |
|
---|
| 492 | HeapDefaultFree(pBuf);
|
---|
| 493 |
|
---|
[24] | 494 | //変更フラグをオフにする
|
---|
[629] | 495 | MdiInfo[WndNum]->pMdiTextEdit->UnModify();
|
---|
[3] | 496 | }
|
---|
[629] | 497 | else if(MdiInfo[WndNum]->DocType==WNDTYPE_ICONEDIT){
|
---|
[3] | 498 | ///////////////////
|
---|
| 499 | // ICON
|
---|
| 500 | ///////////////////
|
---|
| 501 |
|
---|
| 502 | if(SaveFileName){
|
---|
| 503 | lstrcpy(temporary,SaveFileName);
|
---|
[705] | 504 | {
|
---|
| 505 | ATL::CHandle fh(CreateFile(temporary,GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL));
|
---|
| 506 | if(fh==INVALID_HANDLE_VALUE){
|
---|
| 507 | fh.Detach();
|
---|
| 508 | sprintf(str,STRING_FILE_OVERWRIDE,temporary);
|
---|
| 509 | if(MessageBox(hOwner,str,APPLICATION_NAME,MB_YESNO|MB_ICONINFORMATION)==IDNO){
|
---|
| 510 | return 0;
|
---|
| 511 | }
|
---|
[3] | 512 | }
|
---|
| 513 | }
|
---|
[629] | 514 | MdiInfo[WndNum]->path = temporary;
|
---|
[700] | 515 | i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(LONG_PTR)MdiInfo[WndNum]->title.c_str());
|
---|
[3] | 516 | SendMessage(hDocCombo,CB_DELETESTRING,i2,0);
|
---|
| 517 | _splitpath(temporary,NULL,NULL,str,str2);
|
---|
| 518 | lstrcat(str,str2);
|
---|
[629] | 519 | MdiInfo[WndNum]->title = str;
|
---|
[700] | 520 | SendMessage(hDocCombo,CB_ADDSTRING,0,(LONG_PTR)MdiInfo[WndNum]->title.c_str());
|
---|
| 521 | i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(LONG_PTR)MdiInfo[WndNum]->title.c_str());
|
---|
[3] | 522 | SendMessage(hDocCombo,CB_SETCURSEL,i2,0);
|
---|
[629] | 523 | SetWindowText(hChild,MdiInfo[WndNum]->title.c_str());
|
---|
[3] | 524 | }
|
---|
| 525 | else{
|
---|
[629] | 526 | if(MdiInfo[WndNum]->path.empty()){
|
---|
[3] | 527 | //"保存先のファイルを指定してください"
|
---|
| 528 | if(!GetFilePathDialog(hOwner,temporary,IconFileFilter,STRING_FILESAVETITLE_DEFAULT,FALSE)) return 0;
|
---|
| 529 | SaveDocument(hChild,temporary);
|
---|
| 530 | return 1;
|
---|
| 531 | }
|
---|
[629] | 532 | lstrcpy(temporary,MdiInfo[WndNum]->path.c_str());
|
---|
[3] | 533 | }
|
---|
| 534 | SaveIconFile(temporary,hChild);
|
---|
| 535 |
|
---|
[629] | 536 | MdiInfo[WndNum]->MdiIconEditInfo->bModify=0;
|
---|
[3] | 537 | }
|
---|
| 538 |
|
---|
| 539 |
|
---|
| 540 | //タブコントロールを再設定
|
---|
| 541 | if(pobj_nv->bSaveTabToHead){
|
---|
| 542 | COLORREF color;
|
---|
[700] | 543 | color=pobj_MainTab->GetItemColor(oldTitle.c_str());
|
---|
| 544 | pobj_MainTab->DeleteItem( oldTitle.c_str(), false );
|
---|
[629] | 545 | pobj_MainTab->InsertItem( MdiInfo[WndNum]->title.c_str(), false, color );
|
---|
[3] | 546 | }
|
---|
| 547 | else{
|
---|
[700] | 548 | pobj_MainTab->RenameItem( oldTitle.c_str(), MdiInfo[WndNum]->title.c_str() );
|
---|
[3] | 549 | }
|
---|
| 550 |
|
---|
| 551 | //「最近使ったファイル」を更新
|
---|
[629] | 552 | pobj_nv->pobj_History->insert(MdiInfo[WndNum]->path.c_str());
|
---|
[3] | 553 |
|
---|
| 554 | return 1;
|
---|
| 555 | }
|
---|
| 556 | BOOL ShortPathToLongPath(char ShortPath[MAX_PATH],char *LongPath){
|
---|
| 557 | HANDLE hFind;
|
---|
| 558 | WIN32_FIND_DATA wfd;
|
---|
| 559 | int i;
|
---|
| 560 | char dummy[MAX_PATH];
|
---|
| 561 | for(i=0;i<MAX_PATH;i++){
|
---|
| 562 | LongPath[i]=ShortPath[i];
|
---|
| 563 | if((ShortPath[i-1]==':'&&ShortPath[i]=='\\')||(ShortPath[i-1]=='\\'&&ShortPath[i]=='\\')){
|
---|
| 564 | LongPath[i+1]=0;
|
---|
| 565 | break;
|
---|
| 566 | }
|
---|
| 567 | }
|
---|
| 568 | if(ShortPath[i-1]=='\\'&&ShortPath[i]=='\\'){
|
---|
| 569 | for(i++;i<MAX_PATH;i++){
|
---|
| 570 | if(IsDBCSLeadByte(ShortPath[i])){
|
---|
| 571 | i++;
|
---|
| 572 | continue;
|
---|
| 573 | }
|
---|
| 574 | LongPath[i]=ShortPath[i];
|
---|
| 575 | if(ShortPath[i]=='\\'){
|
---|
| 576 | LongPath[i+1]=0;
|
---|
| 577 | break;
|
---|
| 578 | }
|
---|
| 579 | }
|
---|
| 580 | for(i++;i<MAX_PATH;i++){
|
---|
| 581 | if(IsDBCSLeadByte(ShortPath[i])){
|
---|
| 582 | i++;
|
---|
| 583 | continue;
|
---|
| 584 | }
|
---|
| 585 | LongPath[i]=ShortPath[i];
|
---|
| 586 | if(ShortPath[i]=='\\'){
|
---|
| 587 | LongPath[i+1]=0;
|
---|
| 588 | break;
|
---|
| 589 | }
|
---|
| 590 | }
|
---|
| 591 | }
|
---|
| 592 | for(i++;i<MAX_PATH;i++){
|
---|
| 593 | if(IsDBCSLeadByte(ShortPath[i])){
|
---|
| 594 | i++;
|
---|
| 595 | continue;
|
---|
| 596 | }
|
---|
| 597 | if(ShortPath[i]=='\\'||ShortPath[i]=='\0'){
|
---|
| 598 | strncpy(dummy,ShortPath,i);
|
---|
| 599 | dummy[i]=0;
|
---|
| 600 | if((hFind=FindFirstFile(dummy,&wfd))!=INVALID_HANDLE_VALUE) FindClose(hFind);
|
---|
| 601 | lstrcat(LongPath,wfd.cFileName);
|
---|
| 602 |
|
---|
| 603 | if(ShortPath[i]=='\0') break;
|
---|
| 604 | lstrcat(LongPath,"\\");
|
---|
| 605 |
|
---|
| 606 | if(ShortPath[i]=='\\'&&ShortPath[i+1]=='\0'){
|
---|
| 607 | break;
|
---|
| 608 | }
|
---|
| 609 | }
|
---|
| 610 | }
|
---|
| 611 | return 1;
|
---|
| 612 | }
|
---|
| 613 |
|
---|
[22] | 614 | bool IsExistFile( const char *FilePath ){
|
---|
[3] | 615 | WIN32_FIND_DATA wfd;
|
---|
| 616 | HANDLE hFind;
|
---|
| 617 |
|
---|
[22] | 618 | hFind = FindFirstFile(FilePath,&wfd);
|
---|
| 619 | if( hFind == INVALID_HANDLE_VALUE ){
|
---|
| 620 | return false;
|
---|
[3] | 621 | }
|
---|
[22] | 622 | FindClose( hFind );
|
---|
[3] | 623 |
|
---|
[22] | 624 | return true;
|
---|
[3] | 625 | }
|
---|
[22] | 626 |
|
---|
| 627 | bool IsExistDirectory( const char *DirPath ){
|
---|
| 628 | WIN32_FIND_DATA wfd;
|
---|
| 629 | HANDLE hFind;
|
---|
| 630 |
|
---|
| 631 | hFind = FindFirstFile(DirPath,&wfd);
|
---|
| 632 | if( hFind == INVALID_HANDLE_VALUE ){
|
---|
| 633 | //存在しない
|
---|
| 634 | return false;
|
---|
| 635 | }
|
---|
| 636 | FindClose( hFind );
|
---|
| 637 |
|
---|
| 638 | if( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ){
|
---|
| 639 | //ディレクトリの場合
|
---|
| 640 | return true;
|
---|
| 641 | }
|
---|
| 642 |
|
---|
| 643 | //存在しない
|
---|
| 644 | return false;
|
---|
| 645 | }
|
---|