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