source: dev/trunk/ab5.0/abdev/abdev/src/ProjectManager/ProjectManager.cpp @ 619

Last change on this file since 619 was 619, checked in by dai_9181, 15 years ago

Projectクラスをリファクタリング中。

File size: 11.7 KB
Line 
1#include "stdafx.h"
2
3using namespace ActiveBasic::IDE;
4
5void OpenWorkfile( const std::string &path );
6
7void Project::Open( char *path )
8{
9    extern HANDLE hHeap;
10    int i,i2;
11    char *buffer,temporary[MAX_PATH],temp2[MAX_PATH];
12
13    //既にプロジェクトが開かれている場合は閉じる
14    if( this->IsOpened() ){
15        if(!this->Close()) return;
16    }
17    //memset(&projectInfo,0,sizeof(PROJECTINFO));
18
19    //プロジェクトの作業ディレクトリを取得
20    _splitpath(path,this->dir,temporary,0,0);
21    lstrcat(this->dir,temporary);
22
23    //ファイルを開く、保存の初期ディレクトリをセット
24    lstrcpy(pobj_nv->DefSaveDir,this->dir);
25
26
27    //////////////////////////////////////////
28    // リソースデータ用領域を確保
29    this->res.pCursorResInfo=(RESITEMINFO *)HeapAlloc(hHeap,0,1);
30    this->res.NumberOfCursorRes=0;
31    this->res.pBitmapResInfo=(RESITEMINFO *)HeapAlloc(hHeap,0,1);
32    this->res.NumberOfBitmapRes=0;
33    this->res.pIconResInfo=(RESITEMINFO *)HeapAlloc(hHeap,0,1);
34    this->res.NumberOfIconRes=0;
35
36
37    //////////////////////////////////////////
38    //プロジェクトファイル(*.pj)をオープン
39    buffer=ReadBuffer(path);
40    if(!buffer) return;
41
42    //解析
43    this->pobj_DBFileInfo=new CDBFileInfo();
44    bool isUseWindow = false;
45    for(i=0;;i++){
46        if(buffer[i]=='\0') break;
47        if(buffer[i]=='\r'&&buffer[i+1]=='\n'&&buffer[i+2]=='#'){
48            for(i+=3,i2=0;;i++,i2++){
49                if(!IsVariableChar(buffer[i])){
50                    temporary[i2]=0;
51                    break;
52                }
53                temporary[i2]=buffer[i];
54            }
55            if(lstrcmpi(temporary,"VERSION")==0&&buffer[i]=='='){
56                for(i++,i2=0;;i++,i2++){
57                    if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
58                        temporary[i2]=0;
59                        if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
60                        break;
61                    }
62                    temporary[i2]=buffer[i];
63                }
64                this->dwVersion=GetValue(temporary);
65            }
66            else if(lstrcmpi(temporary,"MODULETYPE")==0&&buffer[i]=='='){
67                for(i++,i2=0;;i++,i2++){
68                    if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
69                        temporary[i2]=0;
70                        if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
71                        break;
72                    }
73                    temporary[i2]=buffer[i];
74                }
75                this->moduleType = (ActiveBasic::Common::TargetModuleType::EnumType)atoi(temporary);
76            }
77            else if(lstrcmpi(temporary,"NAME")==0&&buffer[i]=='='){
78                for(i++,i2=0;;i++,i2++){
79                    if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
80                        temporary[i2]=0;
81                        break;
82                    }
83                    temporary[i2]=buffer[i];
84                }
85                this->name = temporary;
86            }
87            else if(lstrcmpi(temporary,"PLATFORM")==0&&buffer[i]=='='){
88                for(i++,i2=0;;i++,i2++){
89                    if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
90                        temporary[i2]=0;
91                        if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
92                        break;
93                    }
94                    temporary[i2]=buffer[i];
95                }
96                i2=atoi(temporary);
97                extern HWND hSelectCompilerCombo;
98                if(i2==32){
99                    //プラットフォームにWin32を選択
100                    SendMessage(hSelectCompilerCombo,CB_SETCURSEL,0,0);
101                }
102                else if(i2==64){
103                    //プラットフォームにWin64を選択
104                    SendMessage(hSelectCompilerCombo,CB_SETCURSEL,1,0);
105                }
106                SendMessage(hSelectCompilerCombo,WM_COMMAND,MAKELONG(0,CBN_SELCHANGE),0);
107            }
108            else if(lstrcmpi(temporary,"USEWINDOW")==0&&buffer[i]=='='){
109                for(i++,i2=0;;i++,i2++){
110                    if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
111                        temporary[i2]=0;
112                        if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
113                        break;
114                    }
115                    temporary[i2]=buffer[i];
116                }
117                if( atoi(temporary) > 0 )
118                {
119                    isUseWindow = true;
120                }
121            }
122            else if(lstrcmpi(temporary,"OPTION")==0&&buffer[i]=='='){
123                for(i++,i2=0;;i++,i2++){
124                    if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
125                        temporary[i2]=0;
126                        if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
127                        break;
128                    }
129                    temporary[i2]=buffer[i];
130                }
131                this->dwOption=GetValue(temporary);
132            }
133            else if(lstrcmpi(temporary,"OUTPUT_RELEASE")==0&&buffer[i]=='='){
134                for(i++,i2=0;;i++,i2++){
135                    if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
136                        temporary[i2]=0;
137                        if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
138                        break;
139                    }
140                    temporary[i2]=buffer[i];
141                }
142                lstrcpy(this->lpszOutput_Release,temporary);
143            }
144            else if(lstrcmpi(temporary,"OUTPUT_DEBUG")==0&&buffer[i]=='='){
145                for(i++,i2=0;;i++,i2++){
146                    if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
147                        temporary[i2]=0;
148                        if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
149                        break;
150                    }
151                    temporary[i2]=buffer[i];
152                }
153                lstrcpy(this->lpszOutput_Debug,temporary);
154            }
155            else if(lstrcmpi(temporary,"MANIFEST")==0&&buffer[i]=='='){
156                for(i++,i2=0;;i++,i2++){
157                    if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
158                        temporary[i2]=0;
159                        if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
160                        break;
161                    }
162                    temporary[i2]=buffer[i];
163                }
164                lstrcpy(this->szManifestPath,temporary);
165            }
166            else if(lstrcmpi(temporary,"DEBUG_CMD_LINE")==0&&buffer[i]=='='){
167                for(i++,i2=0;;i++,i2++){
168                    if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
169                        temporary[i2]=0;
170                        if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
171                        break;
172                    }
173                    temporary[i2]=buffer[i];
174                }
175                lstrcpy(this->szCmdLine,temporary);
176            }
177            else if(lstrcmpi(temporary,"DEBUG_EXE_PATH")==0&&buffer[i]=='='){
178                for(i++,i2=0;;i++,i2++){
179                    if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
180                        temporary[i2]=0;
181                        if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
182                        break;
183                    }
184                    temporary[i2]=buffer[i];
185                }
186                lstrcpy(this->szExePath,temporary);
187            }
188            else if(lstrcmpi(temporary,"RESOURCE")==0&&buffer[i]=='='){
189                for(i++,i2=0;;i++,i2++){
190                    if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
191                        temporary[i2]=0;
192                        if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
193                        break;
194                    }
195                    temporary[i2]=buffer[i];
196                }
197                if(temporary[0]!='\0'&&(!(temporary[0]=='0'&&temporary[1]=='\0'))){
198                    lstrcpy(this->ResourceFileName,temporary);
199                    GetResourceData();
200                }
201                else{
202                    sprintf(this->ResourceFileName,"%s.rc",this->GetName().c_str());
203                }
204            }
205            else if(lstrcmpi(temporary,"SOURCE")==0&&buffer[i]=='\r'&&buffer[i+1]=='\n'){
206                while(1){
207                    for(i+=2,i2=0;;i++,i2++){
208                        if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
209                            temporary[i2]=0;
210                            break;
211                        }
212                        temporary[i2]=buffer[i];
213                    }
214                    if(temporary[0]=='\0') break;
215                    this->pobj_DBFileInfo->add(temporary,0);
216
217                    if(buffer[i]=='\0') break;
218                }
219            }
220            else{
221                //不明なパラメータは無視
222                for(i++;;i++){
223                    if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
224                        if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
225                        break;
226                    }
227                }
228            }
229            if(buffer[i]=='\0') break;
230        }
231    }
232    HeapDefaultFree(buffer);
233
234    //古いバージョンファイルを考慮
235    if(this->dwVersion<=4){
236        if( this->GetModuleType() == ActiveBasic::Common::TargetModuleType::Dll )
237        {
238            sprintf(this->lpszOutput_Release,".\\%s.dll",this->GetName().c_str());
239        }
240        else
241        {
242            sprintf(this->lpszOutput_Release,".\\%s.exe",this->GetName().c_str());
243        }
244        sprintf(this->lpszOutput_Debug,".\\%s_debug.exe",this->GetName().c_str());
245    }
246
247    //ブレークポイントを初期化
248    this->pobj_DBBreakPoint=new CDBBreakPoint();
249
250
251    if( isUseWindow )
252    {
253        /////////////////////////////////////////////
254        //ウィンドウ定義ファイル(*.wnd)をオープン
255        sprintf(temp2,"%s%s.wnd",this->dir,this->GetName().c_str());
256        if(!OpenWindowFile(temp2)) return;
257    }
258    else{
259        this->windowInfos.Clear();
260
261        this->NumberOfMenu=0;
262        this->pMenuInfo=(MENU_INFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,1);
263    }
264
265    OpenWorkfile( this->dir + this->GetName() + ".wrk" );
266
267    this->modify=0;
268    this->ModifyOfMaterial=0;
269    this->ModifuOfResource=0;
270}
271
272bool Project::Close()
273{
274    extern HANDLE hHeap;
275    extern MDIINFO MdiInfo[MAX_WNDNUM];
276    int i,i2,WndNum;
277    HWND hChild,hCloseChild;
278    char temporary[MAX_PATH];
279
280
281    //保存確認
282    i=ProjectModifyCheck(0);
283    if(i==0) return false;
284    else if(i==2) MakeWorkFile();
285
286    //プロジェクトに関するMDIウィンドウをすべて閉じる
287    hChild=GetWindow(hClient,GW_CHILD);
288    while(hChild){
289        hCloseChild=hChild;
290        hChild=GetNextWindow(hChild,GW_HWNDNEXT);
291        WndNum=GetWndNum(hCloseChild);
292        if(IS_DOCUMENT_TEXT(MdiInfo[WndNum].DocType)){
293            for(i=0;i<this->pobj_DBFileInfo->iNum;i++){
294                this->pobj_DBFileInfo->ppobj_FileInfo[i]->GetFullPath(temporary);
295                if(lstrcmpi(MdiInfo[WndNum].path,temporary)==0){
296
297                    //変更フラグをオフにする
298                    MdiInfo[WndNum].pMdiTextEdit->UnModify();
299
300                    SendMessage(hCloseChild,WM_CLOSE,0,0);
301                    break;
302                }
303            }
304        }
305        else if(MdiInfo[WndNum].DocType==WNDTYPE_RAD)
306        {
307            BOOST_FOREACH( const WindowInfo *pWindowInfo, windowInfos )
308            {
309                if( pWindowInfo->GetName() == MdiInfo[WndNum].path ){
310                    SendMessage(hCloseChild,WM_CLOSE,0,0);
311                    break;
312                }
313            }
314        }
315        else if(MdiInfo[WndNum].DocType==WNDTYPE_MENU){
316            for(i=0;i<this->NumberOfMenu;i++){
317                if(lstrcmp(MdiInfo[WndNum].path,this->pMenuInfo[i].IdName)==0){
318                    SendMessage(hCloseChild,WM_CLOSE,0,0);
319                    break;
320                }
321            }
322        }
323        else if(MdiInfo[WndNum].DocType==WNDTYPE_ICONEDIT){
324            for(i=0;this->res.NumberOfIconRes;i++){
325                lstrcpy(temporary,this->res.pIconResInfo[i].path);
326                GetFullPath(temporary,this->dir);
327                if(lstrcmpi(MdiInfo[WndNum].path,temporary)==0){
328                    SendMessage(hCloseChild,WM_CLOSE,0,0);
329                    break;
330                }
331            }
332        }
333    }
334
335    //ファイル情報のメモリを解放
336    delete this->pobj_DBFileInfo;
337
338    //ブレークポイントのオブジェクトを解放
339    delete this->pobj_DBBreakPoint;
340
341    //ウィンドウ情報のメモリを解放
342    BOOST_FOREACH( WindowInfo *pWindowInfo, windowInfos )
343    {
344        HeapDefaultFree(pWindowInfo->caption);
345        HeapDefaultFree(pWindowInfo->ClassName);
346        HeapDefaultFree(pWindowInfo->CallBackName);
347        HeapDefaultFree(pWindowInfo->filepath);
348        if(pWindowInfo->MenuID)
349            HeapDefaultFree(pWindowInfo->MenuID);
350        if(pWindowInfo->IconResName)
351            HeapDefaultFree(pWindowInfo->IconResName);
352
353        //子ウィンドウのメモリを解放
354        for(i2=0;i2<pWindowInfo->childWindowInfos.size();i2++){
355            HeapDefaultFree(pWindowInfo->childWindowInfos[i2]->IdName);
356            HeapDefaultFree(pWindowInfo->childWindowInfos[i2]->caption);
357            if(pWindowInfo->childWindowInfos[i2]->Control==CT_IMAGEBOX){
358                //イメージ ボックスの場合
359                HeapDefaultFree(pWindowInfo->childWindowInfos[i2]->ImageCtrlInfo.path);
360            }
361
362            delete pWindowInfo->childWindowInfos[i2];
363        }
364        pWindowInfo->childWindowInfos.clear();
365    }
366    this->windowInfos.Clear();
367
368    //メニュー情報のメモリを解放
369    HeapMenuDataFree(this->pMenuInfo,this->NumberOfMenu,0);
370    HeapDefaultFree(this->pMenuInfo);
371
372    //リソースのメモリを解放
373    for(i=0;i<this->res.NumberOfCursorRes;i++){
374        HeapDefaultFree(this->res.pCursorResInfo[i].IdName);
375        HeapDefaultFree(this->res.pCursorResInfo[i].path);
376    }
377    HeapDefaultFree(this->res.pCursorResInfo);
378    for(i=0;i<this->res.NumberOfBitmapRes;i++){
379        HeapDefaultFree(this->res.pBitmapResInfo[i].IdName);
380        HeapDefaultFree(this->res.pBitmapResInfo[i].path);
381    }
382    HeapDefaultFree(this->res.pBitmapResInfo);
383    for(i=0;i<this->res.NumberOfIconRes;i++){
384        HeapDefaultFree(this->res.pIconResInfo[i].IdName);
385        HeapDefaultFree(this->res.pIconResInfo[i].path);
386    }
387    HeapDefaultFree(this->res.pIconResInfo);
388
389    //プロジェクト ビューを非表示にする
390    extern HWND hProjectView;
391    if(IsWindowVisible(hProjectView)) SendMessage(hOwner,WM_COMMAND,IDM_PROJECTVIEW,0);
392    SetWindowText(hProjectView,"Project View");
393
394    extern HWND hProcedureTreeView;
395    extern HWND hMaterialTreeView;
396    TreeView_DeleteAllItems(pobj_FileTree->hTree);
397    TreeView_DeleteAllItems(hProcedureTreeView);
398    TreeView_DeleteAllItems(hMaterialTreeView);
399
400    //ウィンドウ タイトルを変更
401    SetWindowText(hOwner,APPLICATION_NAME);
402
403    this->name = "";
404
405    //メニュー状態を設定
406    ResetState_DocMenu();
407
408    return true;
409}
Note: See TracBrowser for help on using the repository browser.