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