source: dev/trunk/ab5.0/abdev/ProjectEditor/Backup.cpp@ 477

Last change on this file since 477 was 475, checked in by dai_9181, 17 years ago

構成管理を変更中・・・(いったんコミット)

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