#include "stdafx.h" using namespace ActiveBasic::PM; void OpenWorkfile( const std::string &path ); void Project::Load( char const *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,temporary,temp2,0,0); lstrcat( temporary, temp2 ); this->workDir = Jenga::Common::Directory( temporary ); //ファイルを開く、保存の初期ディレクトリをセット lstrcpy(pobj_nv->DefSaveDir,this->GetWorkDir().GetPath().c_str()); ////////////////////////////////////////// //プロジェクトファイル(*.pj)をオープン buffer=ReadBuffer(path); if(!buffer) return; //解析 this->fileSystem.root.Clear(); 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]; } // このパラメータは使用しなくなった } 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->fileSystem.root.files.push_back( ActiveBasic::PM::FM::File( 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()); } // リソースを読み込む Jenga::Common::Path resourcePath( this->GetResourceFileFullPath() ); if( resourcePath.IsExistFile() ) { this->resourceManager.Load( this->GetResourceFileFullPath() ); } //ブレークポイントを初期化 this->pobj_DBBreakPoint=new CDBBreakPoint(); if( isUseWindow ) { ///////////////////////////////////////////// //ウィンドウ定義ファイル(*.wnd)をオープン sprintf(temp2,"%s%s.wnd",this->GetWorkDir().GetPath().c_str(),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->GetWorkDir().GetPath() + this->GetName() + ".wrk" ); this->modify=0; this->ModifyOfMaterial=0; this->ModifuOfResource=0; } void SetStatusText(char *MenuText); void MakeSourceListToProjectFile( const ActiveBasic::PM::FM::Folder &folder, char *buffer ) { BOOST_FOREACH( const ActiveBasic::PM::FM::Folder &childFolder, folder.folders ) { MakeSourceListToProjectFile( childFolder, buffer ); } BOOST_FOREACH( const ActiveBasic::PM::FM::File &file, folder.files ) { lstrcat( buffer, file.GetRelationalPath().c_str() ); lstrcat( buffer, "\r\n" ); } } void MakeIncludeListToProjectFile( const ActiveBasic::PM::FM::Folder &folder, char *buffer, bool isRoot ) { BOOST_FOREACH( const ActiveBasic::PM::FM::Folder &childFolder, folder.folders ) { MakeIncludeListToProjectFile( childFolder, buffer, false ); } bool isFirst = true; BOOST_FOREACH( const ActiveBasic::PM::FM::File &file, folder.files ) { if( isRoot && isFirst ) { // メインファイルは除く isFirst = false; continue; } sprintf(buffer+lstrlen(buffer),"#include \"%s\"\r\n",file.GetRelationalPath().c_str()); lstrcpy(buffer+lstrlen(buffer),"_ClearNamespaceImported\r\n"); } } void Project::Save() { int i2,i3,WndNum; char temporary[MAX_PATH],buffer[32767]; HWND hChild; SetStatusText( "プロジェクトを保存中..." ); //プロジェクトファイルのバージョンを設定 this->dwVersion=PROJECT_VERSION; hChild=GetWindow(hClient,GW_CHILD); while(hChild){ WndNum=GetWndNum(hChild); if(IS_DOCUMENT_TEXT(MdiInfo[WndNum]->DocType)){ if( MdiInfo[WndNum]->pMdiTextEdit->IsModified() ) { if( this->fileSystem.root.IsExistFile( MdiInfo[WndNum]->path ) ) { SaveDocument(hChild,NULL); } } } if(MdiInfo[WndNum]->DocType==WNDTYPE_ICONEDIT){ if(MdiInfo[WndNum]->MdiIconEditInfo->bModify){ BOOST_FOREACH( const ActiveBasic::Common::ResourceItem &resourceItem, resourceManager.iconResources ) { lstrcpy(temporary,resourceItem.filepath.c_str()); lstrcpy( temporary, this->GetWorkDir().GetFullPath( temporary ).c_str() ); if(lstrcmpi(MdiInfo[WndNum]->path.c_str(),temporary)==0){ SaveDocument(hChild,NULL); break; } } } } hChild=GetNextWindow(hChild,GW_HWNDNEXT); } ////////////////////////////////////// //プロジェクトファイル(*.pj)を作成 lstrcpy(buffer,"\' ActiveBasic Project file.\r\n\r\n"); i2=lstrlen(buffer); sprintf(buffer+i2,"#VERSION=%d\r\n\r\n",this->dwVersion); i2+=lstrlen(buffer+i2); sprintf(buffer+i2,"#MODULETYPE=%d\r\n\r\n",(int)this->GetModuleType()); i2+=lstrlen(buffer+i2); sprintf(buffer+i2,"#NAME=%s\r\n\r\n",this->GetName().c_str()); i2+=lstrlen(buffer+i2); extern HWND hSelectCompilerCombo; if(SendMessage(hSelectCompilerCombo,CB_GETCURSEL,0,0)==0){ sprintf(buffer+i2,"#PLATFORM=32\r\n\r\n",this->GetName().c_str()); i2+=lstrlen(buffer+i2); } else{ sprintf(buffer+i2,"#PLATFORM=64\r\n\r\n",this->GetName().c_str()); i2+=lstrlen(buffer+i2); } sprintf(buffer+i2,"#USEWINDOW=%d\r\n\r\n",this->windowInfos.size()); i2+=lstrlen(buffer+i2); sprintf(buffer+i2,"#OPTION=&H%08x\r\n\r\n",this->dwOption); i2+=lstrlen(buffer+i2); sprintf(buffer+i2,"#OUTPUT_RELEASE=%s\r\n\r\n",this->lpszOutput_Release); i2+=lstrlen(buffer+i2); sprintf(buffer+i2,"#OUTPUT_DEBUG=%s\r\n\r\n",this->lpszOutput_Debug); i2+=lstrlen(buffer+i2); sprintf(buffer+i2,"#MANIFEST=%s\r\n\r\n",this->szManifestPath); i2+=lstrlen(buffer+i2); sprintf(buffer+i2,"#DEBUG_CMD_LINE=%s\r\n\r\n",this->szCmdLine); i2+=lstrlen(buffer+i2); sprintf(buffer+i2,"#DEBUG_EXE_PATH=%s\r\n\r\n",this->szExePath); i2+=lstrlen(buffer+i2); sprintf(buffer+i2,"#SOURCE\r\n"); i2+=lstrlen(buffer+i2); MakeSourceListToProjectFile( this->fileSystem.root, buffer ); i2 = lstrlen( buffer ); //保存 sprintf(temporary,"%s%s.pj",this->GetWorkDir().GetPath().c_str(),this->GetName().c_str()); WriteBuffer(temporary,buffer,i2); ////////////////////////////////// // リソースファイル(*.rc、resource.ab)を作成 { i2=0; i3=101; BOOST_FOREACH( const ActiveBasic::Common::ResourceItem &resourceItem, resourceManager.cursorResources ) { sprintf(buffer+i2,"Const %s=%d\r\n", resourceItem.idName.c_str(), i3); i2+=lstrlen(buffer+i2); i3++; } BOOST_FOREACH( const ActiveBasic::Common::ResourceItem &resourceItem, resourceManager.bitmapResources ) { sprintf(buffer+i2,"Const %s=%d\r\n", resourceItem.idName.c_str(), i3); i2+=lstrlen(buffer+i2); i3++; } BOOST_FOREACH( const ActiveBasic::Common::ResourceItem &resourceItem, resourceManager.iconResources ) { sprintf(buffer+i2,"Const %s=%d\r\n", resourceItem.idName.c_str(), i3); i2+=lstrlen(buffer+i2); i3++; } //保存(resource.ab) WriteBuffer(this->GetWorkDir().GetFullPath( "resource.ab" ),buffer,i2); i2=0; BOOST_FOREACH( const ActiveBasic::Common::ResourceItem &resourceItem, resourceManager.cursorResources ) { sprintf(buffer+i2,"%s CURSOR \"%s\"\r\n", resourceItem.idName.c_str(), resourceItem.filepath.c_str()); i2+=lstrlen(buffer+i2); } BOOST_FOREACH( const ActiveBasic::Common::ResourceItem &resourceItem, resourceManager.bitmapResources ) { sprintf(buffer+i2,"%s BITMAP \"%s\"\r\n", resourceItem.idName.c_str(), resourceItem.filepath.c_str()); i2+=lstrlen(buffer+i2); } BOOST_FOREACH( const ActiveBasic::Common::ResourceItem &resourceItem, resourceManager.iconResources ) { sprintf(buffer+i2,"%s ICON \"%s\"\r\n", resourceItem.idName.c_str(), resourceItem.filepath.c_str()); i2+=lstrlen(buffer+i2); } //マニフェスト if(this->dwOption&PJ_OP_RC_MANIFEST){ sprintf(buffer+i2,"CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST \"%s\"\r\n", this->szManifestPath); i2+=lstrlen(buffer+i2); } //保存 WriteBuffer(this->GetResourceFileFullPath(),buffer,i2); } /////////////////////////////////////// //インデックスファイル(*.idx)を作成 buffer[0]=0; lstrcpy(buffer,"' インデックス プログラム\r\n"); i2=lstrlen(buffer); if(this->dwOption&PJ_OP_SOURCE_MASK){ if(this->dwOption&PJ_OP_STRICT){ /* #strictディレクティブは今は使われていない lstrcpy(buffer+i2,"\r\n"); i2+=lstrlen(buffer+i2); lstrcpy(buffer+i2,"#strict"); i2+=lstrlen(buffer+i2); lstrcpy(buffer+i2,"\r\n"); i2+=lstrlen(buffer+i2); */ } lstrcpy(buffer+i2,"\r\n"); i2+=lstrlen(buffer+i2); lstrcpy(buffer+i2,"'Win32APIの定義ファイル\r\n"); i2+=lstrlen(buffer+i2); if(this->dwOption&PJ_OP_MMSYSTEM){ lstrcpy(buffer+i2,"#include \r\n"); i2+=lstrlen(buffer+i2); } if(this->dwOption&PJ_OP_COMMCTRL){ lstrcpy(buffer+i2,"#include \r\n"); i2+=lstrlen(buffer+i2); } if(this->dwOption&PJ_OP_RICHEDIT){ lstrcpy(buffer+i2,"#include \r\n"); i2+=lstrlen(buffer+i2); } if(this->dwOption&PJ_OP_WINSOCK){ lstrcpy(buffer+i2,"#include \r\n"); i2+=lstrlen(buffer+i2); } } if( !this->windowInfos.empty() ) { lstrcpy(buffer+i2,"\r\n"); i2+=lstrlen(buffer+i2); lstrcpy(buffer+i2,"'RADツールが生成するウィンドウ制御プログラム\r\n"); i2+=lstrlen(buffer+i2); sprintf(buffer+i2,"#include \"Callback.wbp\"\r\n"); i2+=lstrlen(buffer+i2); } { lstrcpy(buffer+i2,"\r\n"); i2+=lstrlen(buffer+i2); lstrcpy(buffer+i2,"'プロジェクト内のプログラム ファイル\r\n"); i2+=lstrlen(buffer+i2); MakeIncludeListToProjectFile( this->fileSystem.root, buffer, true ); i2 = lstrlen(buffer); } if( !this->windowInfos.empty() ) { lstrcpy(buffer+i2,"\r\n"); i2+=lstrlen(buffer+i2); lstrcpy(buffer+i2,"'RADツールが生成するウィンドウ生成プログラム\r\n"); i2+=lstrlen(buffer+i2); sprintf(buffer+i2,"#include \"MakeWindow.wbp\"\r\n"); i2+=lstrlen(buffer+i2); } //リソースファイル lstrcpy(buffer+i2,"\r\n"); i2+=lstrlen(buffer+i2); lstrcpy(buffer+i2,"'リソースファイル\r\n"); i2+=lstrlen(buffer+i2); lstrcpy(buffer+i2,"#include \"resource.ab\"\r\n"); i2+=lstrlen(buffer+i2); sprintf(buffer+i2,"#resource \"%s.rc\"\r\n",this->GetName().c_str()); i2+=lstrlen(buffer+i2); //保存 sprintf(temporary,"%s%s.idx",this->GetWorkDir().GetPath().c_str(),this->GetName().c_str()); WriteBuffer(temporary,buffer,i2); if( !this->windowInfos.empty() ) { ///////////////////////////////////////////////////// //ウィンドウ関連ファイル(*.wnd)を作成、保存 if(this->ModifyOfMaterial){ sprintf(temporary,"%s%s.wnd",this->GetWorkDir().GetPath().c_str(),this->GetName().c_str()); SaveWindowFile( temporary, this->windowInfos ); } //.wbpファイルを生成 SaveWindowProgram(); } MakeWorkFile(); SetStatusText(""); this->modify=0; this->ModifuOfResource=0; } bool Project::Close() { extern HANDLE hHeap; int i,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)) { if( this->fileSystem.root.IsExistFile( MdiInfo[WndNum]->path ) ) { //変更フラグをオフにする MdiInfo[WndNum]->pMdiTextEdit->UnModify(); SendMessage(hCloseChild,WM_CLOSE,0,0); } } 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;iNumberOfMenu;i++){ if( MdiInfo[WndNum]->path == this->pMenuInfo[i].IdName ) { SendMessage(hCloseChild,WM_CLOSE,0,0); break; } } } else if(MdiInfo[WndNum]->DocType==WNDTYPE_ICONEDIT){ for(i=0;this->resourceManager.iconResources.size();i++){ lstrcpy(temporary,this->resourceManager.iconResources[i].filepath.c_str()); lstrcpy( temporary, this->GetWorkDir().GetFullPath( temporary ).c_str() ); if(lstrcmpi(MdiInfo[WndNum]->path.c_str(),temporary)==0){ SendMessage(hCloseChild,WM_CLOSE,0,0); break; } } } } //ファイル情報のメモリを解放 this->fileSystem.root.Clear(); //ブレークポイントのオブジェクトを解放 delete this->pobj_DBBreakPoint; //ウィンドウ情報のメモリを解放 BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, windowInfos ) { //子ウィンドウのメモリを解放 BOOST_FOREACH( ActiveBasic::PM::ChildWindowInfo *pChildWindowInfo, pWindowInfo->childWindowInfos ) { delete pChildWindowInfo; } pWindowInfo->childWindowInfos.clear(); } this->windowInfos.Clear(); //メニュー情報のメモリを解放 HeapMenuDataFree(this->pMenuInfo,this->NumberOfMenu,0); HeapDefaultFree(this->pMenuInfo); //リソースのメモリを解放 this->resourceManager.Clear(); //プロジェクト ビューを非表示にする extern HWND hProjectView; if(IsWindowVisible(hProjectView)) SendMessage(hOwner,WM_COMMAND,IDM_PROJECTVIEW,0); SetWindowText(hProjectView,"Project View"); extern HWND hProcedureTreeView; extern HWND hMaterialTreeView; pobj_FileTree->DeleteAllItems(); TreeView_DeleteAllItems(hProcedureTreeView); TreeView_DeleteAllItems(hMaterialTreeView); //ウィンドウ タイトルを変更 SetWindowText(hOwner,APPLICATION_NAME); this->name = ""; //メニュー状態を設定 ResetState_DocMenu(); return true; }