Index: trunk/ab5.0/abdev/abdev/src/ProjectManager/ProjectManager.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/src/ProjectManager/ProjectManager.cpp	(revision 615)
+++ trunk/ab5.0/abdev/abdev/src/ProjectManager/ProjectManager.cpp	(revision 619)
@@ -1,1 +1,409 @@
 #include "stdafx.h"
+
+using namespace ActiveBasic::IDE;
+
+void OpenWorkfile( const std::string &path );
+
+void Project::Open( char *path )
+{
+	extern HANDLE hHeap;
+	int i,i2;
+	char *buffer,temporary[MAX_PATH],temp2[MAX_PATH];
+
+	//既にプロジェクトが開かれている場合は閉じる
+	if( this->IsOpened() ){
+		if(!this->Close()) return;
+	}
+	//memset(&projectInfo,0,sizeof(PROJECTINFO));
+
+	//プロジェクトの作業ディレクトリを取得
+	_splitpath(path,this->dir,temporary,0,0);
+	lstrcat(this->dir,temporary);
+
+	//ファイルを開く、保存の初期ディレクトリをセット
+	lstrcpy(pobj_nv->DefSaveDir,this->dir);
+
+
+	//////////////////////////////////////////
+	// リソースデータ用領域を確保
+	this->res.pCursorResInfo=(RESITEMINFO *)HeapAlloc(hHeap,0,1);
+	this->res.NumberOfCursorRes=0;
+	this->res.pBitmapResInfo=(RESITEMINFO *)HeapAlloc(hHeap,0,1);
+	this->res.NumberOfBitmapRes=0;
+	this->res.pIconResInfo=(RESITEMINFO *)HeapAlloc(hHeap,0,1);
+	this->res.NumberOfIconRes=0;
+
+
+	//////////////////////////////////////////
+	//プロジェクトファイル（*.pj）をオープン
+	buffer=ReadBuffer(path);
+	if(!buffer) return;
+
+	//解析
+	this->pobj_DBFileInfo=new CDBFileInfo();
+	bool isUseWindow = false;
+	for(i=0;;i++){
+		if(buffer[i]=='\0') break;
+		if(buffer[i]=='\r'&&buffer[i+1]=='\n'&&buffer[i+2]=='#'){
+			for(i+=3,i2=0;;i++,i2++){
+				if(!IsVariableChar(buffer[i])){
+					temporary[i2]=0;
+					break;
+				}
+				temporary[i2]=buffer[i];
+			}
+			if(lstrcmpi(temporary,"VERSION")==0&&buffer[i]=='='){
+				for(i++,i2=0;;i++,i2++){
+					if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
+						temporary[i2]=0;
+						if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
+						break;
+					}
+					temporary[i2]=buffer[i];
+				}
+				this->dwVersion=GetValue(temporary);
+			}
+			else if(lstrcmpi(temporary,"MODULETYPE")==0&&buffer[i]=='='){
+				for(i++,i2=0;;i++,i2++){
+					if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
+						temporary[i2]=0;
+						if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
+						break;
+					}
+					temporary[i2]=buffer[i];
+				}
+				this->moduleType = (ActiveBasic::Common::TargetModuleType::EnumType)atoi(temporary);
+			}
+			else if(lstrcmpi(temporary,"NAME")==0&&buffer[i]=='='){
+				for(i++,i2=0;;i++,i2++){
+					if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
+						temporary[i2]=0;
+						break;
+					}
+					temporary[i2]=buffer[i];
+				}
+				this->name = temporary;
+			}
+			else if(lstrcmpi(temporary,"PLATFORM")==0&&buffer[i]=='='){
+				for(i++,i2=0;;i++,i2++){
+					if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
+						temporary[i2]=0;
+						if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
+						break;
+					}
+					temporary[i2]=buffer[i];
+				}
+				i2=atoi(temporary);
+				extern HWND hSelectCompilerCombo;
+				if(i2==32){
+					//プラットフォームにWin32を選択
+					SendMessage(hSelectCompilerCombo,CB_SETCURSEL,0,0);
+				}
+				else if(i2==64){
+					//プラットフォームにWin64を選択
+					SendMessage(hSelectCompilerCombo,CB_SETCURSEL,1,0);
+				}
+				SendMessage(hSelectCompilerCombo,WM_COMMAND,MAKELONG(0,CBN_SELCHANGE),0);
+			}
+			else if(lstrcmpi(temporary,"USEWINDOW")==0&&buffer[i]=='='){
+				for(i++,i2=0;;i++,i2++){
+					if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
+						temporary[i2]=0;
+						if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
+						break;
+					}
+					temporary[i2]=buffer[i];
+				}
+				if( atoi(temporary) > 0 )
+				{
+					isUseWindow = true;
+				}
+			}
+			else if(lstrcmpi(temporary,"OPTION")==0&&buffer[i]=='='){
+				for(i++,i2=0;;i++,i2++){
+					if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
+						temporary[i2]=0;
+						if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
+						break;
+					}
+					temporary[i2]=buffer[i];
+				}
+				this->dwOption=GetValue(temporary);
+			}
+			else if(lstrcmpi(temporary,"OUTPUT_RELEASE")==0&&buffer[i]=='='){
+				for(i++,i2=0;;i++,i2++){
+					if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
+						temporary[i2]=0;
+						if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
+						break;
+					}
+					temporary[i2]=buffer[i];
+				}
+				lstrcpy(this->lpszOutput_Release,temporary);
+			}
+			else if(lstrcmpi(temporary,"OUTPUT_DEBUG")==0&&buffer[i]=='='){
+				for(i++,i2=0;;i++,i2++){
+					if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
+						temporary[i2]=0;
+						if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
+						break;
+					}
+					temporary[i2]=buffer[i];
+				}
+				lstrcpy(this->lpszOutput_Debug,temporary);
+			}
+			else if(lstrcmpi(temporary,"MANIFEST")==0&&buffer[i]=='='){
+				for(i++,i2=0;;i++,i2++){
+					if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
+						temporary[i2]=0;
+						if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
+						break;
+					}
+					temporary[i2]=buffer[i];
+				}
+				lstrcpy(this->szManifestPath,temporary);
+			}
+			else if(lstrcmpi(temporary,"DEBUG_CMD_LINE")==0&&buffer[i]=='='){
+				for(i++,i2=0;;i++,i2++){
+					if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
+						temporary[i2]=0;
+						if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
+						break;
+					}
+					temporary[i2]=buffer[i];
+				}
+				lstrcpy(this->szCmdLine,temporary);
+			}
+			else if(lstrcmpi(temporary,"DEBUG_EXE_PATH")==0&&buffer[i]=='='){
+				for(i++,i2=0;;i++,i2++){
+					if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
+						temporary[i2]=0;
+						if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
+						break;
+					}
+					temporary[i2]=buffer[i];
+				}
+				lstrcpy(this->szExePath,temporary);
+			}
+			else if(lstrcmpi(temporary,"RESOURCE")==0&&buffer[i]=='='){
+				for(i++,i2=0;;i++,i2++){
+					if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
+						temporary[i2]=0;
+						if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
+						break;
+					}
+					temporary[i2]=buffer[i];
+				}
+				if(temporary[0]!='\0'&&(!(temporary[0]=='0'&&temporary[1]=='\0'))){
+					lstrcpy(this->ResourceFileName,temporary);
+					GetResourceData();
+				}
+				else{
+					sprintf(this->ResourceFileName,"%s.rc",this->GetName().c_str());
+				}
+			}
+			else if(lstrcmpi(temporary,"SOURCE")==0&&buffer[i]=='\r'&&buffer[i+1]=='\n'){
+				while(1){
+					for(i+=2,i2=0;;i++,i2++){
+						if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
+							temporary[i2]=0;
+							break;
+						}
+						temporary[i2]=buffer[i];
+					}
+					if(temporary[0]=='\0') break;
+					this->pobj_DBFileInfo->add(temporary,0);
+
+					if(buffer[i]=='\0') break;
+				}
+			}
+			else{
+				//不明なパラメータは無視
+				for(i++;;i++){
+					if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
+						if(buffer[i]=='\r'&&buffer[i+1]=='\n') i-=2;
+						break;
+					}
+				}
+			}
+			if(buffer[i]=='\0') break;
+		}
+	}
+	HeapDefaultFree(buffer);
+
+	//古いバージョンファイルを考慮
+	if(this->dwVersion<=4){
+		if( this->GetModuleType() == ActiveBasic::Common::TargetModuleType::Dll )
+		{
+			sprintf(this->lpszOutput_Release,".\\%s.dll",this->GetName().c_str());
+		}
+		else
+		{
+			sprintf(this->lpszOutput_Release,".\\%s.exe",this->GetName().c_str());
+		}
+		sprintf(this->lpszOutput_Debug,".\\%s_debug.exe",this->GetName().c_str());
+	}
+
+	//ブレークポイントを初期化
+	this->pobj_DBBreakPoint=new CDBBreakPoint();
+
+
+	if( isUseWindow )
+	{
+		/////////////////////////////////////////////
+		//ウィンドウ定義ファイル（*.wnd）をオープン
+		sprintf(temp2,"%s%s.wnd",this->dir,this->GetName().c_str());
+		if(!OpenWindowFile(temp2)) return;
+	}
+	else{
+		this->windowInfos.Clear();
+
+		this->NumberOfMenu=0;
+		this->pMenuInfo=(MENU_INFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,1);
+	}
+
+	OpenWorkfile( this->dir + this->GetName() + ".wrk" );
+
+	this->modify=0;
+	this->ModifyOfMaterial=0;
+	this->ModifuOfResource=0;
+}
+
+bool Project::Close()
+{
+	extern HANDLE hHeap;
+	extern MDIINFO MdiInfo[MAX_WNDNUM];
+	int i,i2,WndNum;
+	HWND hChild,hCloseChild;
+	char temporary[MAX_PATH];
+
+
+	//保存確認
+	i=ProjectModifyCheck(0);
+	if(i==0) return false;
+	else if(i==2) MakeWorkFile();
+
+	//プロジェクトに関するMDIウィンドウをすべて閉じる
+	hChild=GetWindow(hClient,GW_CHILD);
+	while(hChild){
+		hCloseChild=hChild;
+		hChild=GetNextWindow(hChild,GW_HWNDNEXT);
+		WndNum=GetWndNum(hCloseChild);
+		if(IS_DOCUMENT_TEXT(MdiInfo[WndNum].DocType)){
+			for(i=0;i<this->pobj_DBFileInfo->iNum;i++){
+				this->pobj_DBFileInfo->ppobj_FileInfo[i]->GetFullPath(temporary);
+				if(lstrcmpi(MdiInfo[WndNum].path,temporary)==0){
+
+					//変更フラグをオフにする
+					MdiInfo[WndNum].pMdiTextEdit->UnModify();
+
+					SendMessage(hCloseChild,WM_CLOSE,0,0);
+					break;
+				}
+			}
+		}
+		else if(MdiInfo[WndNum].DocType==WNDTYPE_RAD)
+		{
+			BOOST_FOREACH( const WindowInfo *pWindowInfo, windowInfos )
+			{
+				if( pWindowInfo->GetName() == MdiInfo[WndNum].path ){
+					SendMessage(hCloseChild,WM_CLOSE,0,0);
+					break;
+				}
+			}
+		}
+		else if(MdiInfo[WndNum].DocType==WNDTYPE_MENU){
+			for(i=0;i<this->NumberOfMenu;i++){
+				if(lstrcmp(MdiInfo[WndNum].path,this->pMenuInfo[i].IdName)==0){
+					SendMessage(hCloseChild,WM_CLOSE,0,0);
+					break;
+				}
+			}
+		}
+		else if(MdiInfo[WndNum].DocType==WNDTYPE_ICONEDIT){
+			for(i=0;this->res.NumberOfIconRes;i++){
+				lstrcpy(temporary,this->res.pIconResInfo[i].path);
+				GetFullPath(temporary,this->dir);
+				if(lstrcmpi(MdiInfo[WndNum].path,temporary)==0){
+					SendMessage(hCloseChild,WM_CLOSE,0,0);
+					break;
+				}
+			}
+		}
+	}
+
+	//ファイル情報のメモリを解放
+	delete this->pobj_DBFileInfo;
+
+	//ブレークポイントのオブジェクトを解放
+	delete this->pobj_DBBreakPoint;
+
+	//ウィンドウ情報のメモリを解放
+	BOOST_FOREACH( WindowInfo *pWindowInfo, windowInfos )
+	{
+		HeapDefaultFree(pWindowInfo->caption);
+		HeapDefaultFree(pWindowInfo->ClassName);
+		HeapDefaultFree(pWindowInfo->CallBackName);
+		HeapDefaultFree(pWindowInfo->filepath);
+		if(pWindowInfo->MenuID)
+			HeapDefaultFree(pWindowInfo->MenuID);
+		if(pWindowInfo->IconResName)
+			HeapDefaultFree(pWindowInfo->IconResName);
+
+		//子ウィンドウのメモリを解放
+		for(i2=0;i2<pWindowInfo->childWindowInfos.size();i2++){
+			HeapDefaultFree(pWindowInfo->childWindowInfos[i2]->IdName);
+			HeapDefaultFree(pWindowInfo->childWindowInfos[i2]->caption);
+			if(pWindowInfo->childWindowInfos[i2]->Control==CT_IMAGEBOX){
+				//イメージ ボックスの場合
+				HeapDefaultFree(pWindowInfo->childWindowInfos[i2]->ImageCtrlInfo.path);
+			}
+
+			delete pWindowInfo->childWindowInfos[i2];
+		}
+		pWindowInfo->childWindowInfos.clear();
+	}
+	this->windowInfos.Clear();
+
+	//メニュー情報のメモリを解放
+	HeapMenuDataFree(this->pMenuInfo,this->NumberOfMenu,0);
+	HeapDefaultFree(this->pMenuInfo);
+
+	//リソースのメモリを解放
+	for(i=0;i<this->res.NumberOfCursorRes;i++){
+		HeapDefaultFree(this->res.pCursorResInfo[i].IdName);
+		HeapDefaultFree(this->res.pCursorResInfo[i].path);
+	}
+	HeapDefaultFree(this->res.pCursorResInfo);
+	for(i=0;i<this->res.NumberOfBitmapRes;i++){
+		HeapDefaultFree(this->res.pBitmapResInfo[i].IdName);
+		HeapDefaultFree(this->res.pBitmapResInfo[i].path);
+	}
+	HeapDefaultFree(this->res.pBitmapResInfo);
+	for(i=0;i<this->res.NumberOfIconRes;i++){
+		HeapDefaultFree(this->res.pIconResInfo[i].IdName);
+		HeapDefaultFree(this->res.pIconResInfo[i].path);
+	}
+	HeapDefaultFree(this->res.pIconResInfo);
+
+	//プロジェクト ビューを非表示にする
+	extern HWND hProjectView;
+	if(IsWindowVisible(hProjectView)) SendMessage(hOwner,WM_COMMAND,IDM_PROJECTVIEW,0);
+	SetWindowText(hProjectView,"Project View");
+
+	extern HWND hProcedureTreeView;
+	extern HWND hMaterialTreeView;
+	TreeView_DeleteAllItems(pobj_FileTree->hTree);
+	TreeView_DeleteAllItems(hProcedureTreeView);
+	TreeView_DeleteAllItems(hMaterialTreeView);
+
+	//ウィンドウ タイトルを変更
+	SetWindowText(hOwner,APPLICATION_NAME);
+
+	this->name = "";
+
+	//メニュー状態を設定
+	ResetState_DocMenu();
+
+	return true;
+}
