[3] | 1 | #include "common.h"
|
---|
| 2 |
|
---|
| 3 |
|
---|
| 4 | char szBackupDirPath[MAX_PATH];
|
---|
| 5 |
|
---|
| 6 | void CreateBackupDir(void){
|
---|
| 7 | //自動バックアップ用のフォルダを取得
|
---|
| 8 | extern char szBackupDirPath[MAX_PATH];
|
---|
| 9 | GUID guid;
|
---|
| 10 | char *temp2;
|
---|
| 11 | CoCreateGuid(&guid);
|
---|
| 12 | UuidToString(&guid,(unsigned char **)&temp2);
|
---|
| 13 |
|
---|
| 14 | char temporary[MAX_PATH];
|
---|
| 15 | GetTempPath(MAX_PATH,temporary);
|
---|
| 16 | ShortPathToLongPath(temporary,szBackupDirPath);
|
---|
| 17 | if(szBackupDirPath[lstrlen(szBackupDirPath)-1]!='\\') lstrcat(szBackupDirPath,"\\");
|
---|
| 18 |
|
---|
| 19 | #ifdef THETEXT
|
---|
| 20 | lstrcat(szBackupDirPath,"TheText_Temporary_");
|
---|
| 21 | #else
|
---|
[22] | 22 | lstrcat(szBackupDirPath,"abdev_temporary_");
|
---|
[3] | 23 | #endif
|
---|
| 24 | lstrcat(szBackupDirPath,temp2);
|
---|
| 25 | RpcStringFree((unsigned char **)&temp2);
|
---|
| 26 |
|
---|
| 27 | CreateDirectory(szBackupDirPath,NULL);
|
---|
| 28 | lstrcat(szBackupDirPath,"\\");
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | void backup(void *dummy){
|
---|
| 33 | extern char szBackupDirPath[MAX_PATH];
|
---|
| 34 | int i,iNum=0;
|
---|
| 35 | char temporary[MAX_PATH];
|
---|
| 36 |
|
---|
[22] | 37 | lstrcpy( temporary, szBackupDirPath );
|
---|
| 38 | if( temporary[lstrlen(temporary)-1] == '\\' ) temporary[lstrlen(temporary)-1] = 0;
|
---|
| 39 | if( !IsExistDirectory( temporary ) ){
|
---|
| 40 | //バックアップ用一時ディレクトリが存在しないときは作る
|
---|
| 41 | CreateDirectory( temporary, NULL );
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[3] | 44 | char *temp2;
|
---|
| 45 | temp2=(char *)malloc(8192);
|
---|
| 46 | sprintf(temp2,"%x\r\n",hOwner);
|
---|
| 47 |
|
---|
| 48 | for(i=0;i<MAX_WNDNUM;i++){
|
---|
| 49 | if(MdiInfo[i].hwnd){
|
---|
| 50 | int WndNum;
|
---|
| 51 | WndNum=i;
|
---|
| 52 |
|
---|
| 53 | if(!IS_DOCUMENT_TEXT(MdiInfo[WndNum].DocType)) continue;
|
---|
| 54 |
|
---|
| 55 | //ファイルを保存
|
---|
| 56 | sprintf(temporary,"%sdocument%02d.txt",szBackupDirPath,iNum);
|
---|
[24] | 57 | WriteBuffer(temporary,MdiInfo[WndNum].pMdiTextEdit->buffer,lstrlen(MdiInfo[WndNum].pMdiTextEdit->buffer));
|
---|
[3] | 58 |
|
---|
| 59 | //情報を追加
|
---|
| 60 | sprintf(temp2+lstrlen(temp2),"%s\r\n",MdiInfo[WndNum].path);
|
---|
| 61 |
|
---|
| 62 | iNum++;
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | //バックアップヘッダ
|
---|
| 67 | sprintf(temporary,"%sinfo.txt",szBackupDirPath);
|
---|
| 68 | WriteBuffer_NonErrMsg(temporary,temp2,lstrlen(temp2));
|
---|
| 69 |
|
---|
| 70 | free(temp2);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 |
|
---|
[22] | 74 | void RestoreBeforeState(const char *dir_path,char *pHeaderBuffer){
|
---|
[3] | 75 | int i,i2;
|
---|
| 76 | for(i=0;;i++){
|
---|
| 77 | if(pHeaderBuffer[i]=='\0') break;
|
---|
| 78 | if(pHeaderBuffer[i]=='\r'&&pHeaderBuffer[i+1]=='\n') break;
|
---|
| 79 | }
|
---|
| 80 | if(pHeaderBuffer[i]=='\0') return;
|
---|
| 81 | i+=2;
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | int iDocNum=0;
|
---|
| 85 | char temporary[MAX_PATH];
|
---|
| 86 | while(1){
|
---|
| 87 | //元のファイルパスを取得
|
---|
| 88 | char szBeforeFilePath[MAX_PATH];
|
---|
| 89 | for(i2=0;;i++,i2++){
|
---|
| 90 | if(pHeaderBuffer[i]=='\r'&&pHeaderBuffer[i+1]=='\n'){
|
---|
| 91 | szBeforeFilePath[i2]=0;
|
---|
| 92 | break;
|
---|
| 93 | }
|
---|
| 94 | szBeforeFilePath[i2]=pHeaderBuffer[i];
|
---|
| 95 | if(pHeaderBuffer[i]=='\0') break;
|
---|
| 96 | }
|
---|
| 97 | if(pHeaderBuffer[i]=='\0') break;
|
---|
| 98 |
|
---|
| 99 | sprintf(temporary,"%sdocument%02d.txt",dir_path,iDocNum);
|
---|
| 100 |
|
---|
| 101 | HWND hChild;
|
---|
| 102 | hChild=NewTextEditWindow(temporary,WNDTYPE_TEXT);
|
---|
| 103 | int WndNum;
|
---|
| 104 | WndNum=GetWndNum(hChild);
|
---|
| 105 |
|
---|
| 106 | char szOldTitle[MAX_PATH];
|
---|
| 107 | lstrcpy(szOldTitle,MdiInfo[WndNum].title);
|
---|
| 108 |
|
---|
| 109 | //ドキュメント セレクト コンボボックスから消去
|
---|
| 110 | extern HWND hDocCombo;
|
---|
| 111 | i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(long)MdiInfo[WndNum].title);
|
---|
| 112 | SendMessage(hDocCombo,CB_DELETESTRING,i2,0);
|
---|
| 113 |
|
---|
| 114 | //パスを変更
|
---|
| 115 | GlobalFree(MdiInfo[WndNum].path);
|
---|
| 116 | MdiInfo[WndNum].path=(char *)GlobalAlloc(GMEM_FIXED,lstrlen(szBeforeFilePath)+1);
|
---|
| 117 | lstrcpy(MdiInfo[WndNum].path,szBeforeFilePath);
|
---|
| 118 |
|
---|
| 119 | //ドキュメント セレクト コンボボックスに挿入
|
---|
| 120 | char str[MAX_PATH],str2[MAX_PATH];
|
---|
| 121 | if(szBeforeFilePath[0]){
|
---|
| 122 | _splitpath(szBeforeFilePath,NULL,NULL,str,str2);
|
---|
| 123 | lstrcat(str,str2);
|
---|
| 124 | }
|
---|
| 125 | else{
|
---|
| 126 | extern int DocumentCounter;
|
---|
| 127 | DocumentCounter++;
|
---|
| 128 | sprintf(str,"Document[%d]",DocumentCounter);
|
---|
| 129 | }
|
---|
| 130 | DuplicateTitleCheck(str);
|
---|
| 131 | GlobalFree(MdiInfo[WndNum].title);
|
---|
| 132 | MdiInfo[WndNum].title=(char *)GlobalAlloc(GMEM_FIXED,lstrlen(str)+1);
|
---|
| 133 | lstrcpy(MdiInfo[WndNum].title,str);
|
---|
| 134 | SendMessage(hDocCombo,CB_ADDSTRING,0,(long)MdiInfo[WndNum].title);
|
---|
| 135 | i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(long)MdiInfo[WndNum].title);
|
---|
| 136 | SendMessage(hDocCombo,CB_SETCURSEL,i2,0);
|
---|
| 137 |
|
---|
| 138 | //MDIウィンドウのタイトルを再設定
|
---|
| 139 | SetWindowText(hChild,MdiInfo[WndNum].title);
|
---|
| 140 |
|
---|
| 141 | //タブコントロールを再設定
|
---|
| 142 | COLORREF TabColor;
|
---|
| 143 | TabColor=pobj_nv->pobj_ExtLink->GetTabColorFromFilePath(MdiInfo[WndNum].path);
|
---|
[24] | 144 | pobj_MainTab->DeleteItem( szOldTitle, false );
|
---|
| 145 | pobj_MainTab->InsertItem( MdiInfo[WndNum].title, false, TabColor );
|
---|
[3] | 146 |
|
---|
[24] | 147 | MdiInfo[WndNum].pMdiTextEdit->Modify();
|
---|
[3] | 148 |
|
---|
| 149 |
|
---|
| 150 | iDocNum++;
|
---|
| 151 |
|
---|
| 152 | i+=2;
|
---|
| 153 | if(pHeaderBuffer[i]=='\0') break;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | RemoveDirectoryStrong(dir_path);
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 |
|
---|
| 160 | BOOL restore(void){
|
---|
| 161 | HANDLE hFind;
|
---|
| 162 | WIN32_FIND_DATA wfd;
|
---|
| 163 | char temporary[MAX_PATH],*temp2;
|
---|
| 164 |
|
---|
| 165 | char szTempPath[MAX_PATH];
|
---|
| 166 | GetTempPath(MAX_PATH,temporary);
|
---|
| 167 | ShortPathToLongPath(temporary,szTempPath);
|
---|
| 168 | if(szTempPath[lstrlen(szTempPath)-1]!='\\') lstrcat(szTempPath,"\\");
|
---|
| 169 |
|
---|
| 170 | sprintf(temporary,"%s*",szTempPath);
|
---|
| 171 | hFind=FindFirstFile(temporary,&wfd);
|
---|
| 172 | if(hFind!=INVALID_HANDLE_VALUE){
|
---|
| 173 | do{
|
---|
| 174 | if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
|
---|
| 175 | #ifdef THETEXT
|
---|
| 176 | if(memcmp(wfd.cFileName,"TheText_Temporary_",18)==0){
|
---|
| 177 | #else
|
---|
[22] | 178 | if(memcmp(wfd.cFileName,"abdev_temporary_",16)==0){
|
---|
[3] | 179 | #endif
|
---|
| 180 | sprintf(temporary,"%s%s\\info.txt",szTempPath,wfd.cFileName);
|
---|
| 181 | temp2=ReadBuffer_NonErrMsg(temporary);
|
---|
| 182 | if(temp2){
|
---|
| 183 | HWND hTemp;
|
---|
| 184 | sscanf(temp2,"%x",&hTemp);
|
---|
| 185 | if(!IsWindow(hTemp)){
|
---|
| 186 | sprintf(temporary,"前回、%sが異常終了した可能性があります。データを復元しますか?",APPLICATION_NAME);
|
---|
| 187 | if(MessageBox(hOwner,temporary,APPLICATION_NAME,MB_YESNO)==IDNO){
|
---|
| 188 | HeapDefaultFree(temp2);
|
---|
| 189 |
|
---|
| 190 | sprintf(temporary,"%s%s\\",szTempPath,wfd.cFileName);
|
---|
| 191 | RemoveDirectoryStrong(temporary);
|
---|
| 192 | return 0;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | sprintf(temporary,"%s%s\\",szTempPath,wfd.cFileName);
|
---|
| 196 | RestoreBeforeState(temporary,temp2);
|
---|
| 197 |
|
---|
| 198 | HeapDefaultFree(temp2);
|
---|
| 199 |
|
---|
| 200 | return 1;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | HeapDefaultFree(temp2);
|
---|
| 204 | }
|
---|
| 205 | }
|
---|
| 206 | }
|
---|
| 207 | }while(FindNextFile(hFind,&wfd));
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | return 0;
|
---|
| 211 | }
|
---|