[commit] r1333 - in trunk/GME: Common GMEActiveBrowser Gme Mga

GMESRC Repository Notifications gme-commit at list.isis.vanderbilt.edu
Wed Jun 1 14:54:04 CDT 2011


Author: ksmyth
Date: Wed Jun  1 14:54:04 2011
New Revision: 1333

Log:
Support relative paths in library refresh

Modified:
   trunk/GME/Common/CommonMfc.h
   trunk/GME/GMEActiveBrowser/ActiveBrowserPropertyPage.cpp
   trunk/GME/GMEActiveBrowser/AttachLibDlg.cpp
   trunk/GME/GMEActiveBrowser/AttachLibDlg.h
   trunk/GME/GMEActiveBrowser/GMEActiveBrowser.rc
   trunk/GME/GMEActiveBrowser/resource.h
   trunk/GME/Gme/MgaOpenDlg.cpp
   trunk/GME/Mga/MgaLibOps.cpp

Modified: trunk/GME/Common/CommonMfc.h
==============================================================================
--- trunk/GME/Common/CommonMfc.h	Tue May 31 17:00:25 2011	(r1332)
+++ trunk/GME/Common/CommonMfc.h	Wed Jun  1 14:54:04 2011	(r1333)
@@ -240,6 +240,23 @@
 	return ret;
 }
 
+static void GetFullPathName(const CString& path, CString& filename, CString& dirname) {
+	TCHAR currentMgaPath[MAX_PATH];
+	TCHAR* tcfilename;
+	if (!GetFullPathName(path, MAX_PATH, currentMgaPath, &tcfilename) || tcfilename == 0) {
+	} else {
+		filename = tcfilename;
+		*(tcfilename-1) = '\0';
+		dirname = currentMgaPath;
+	}
+}
+
+static CString ConnStrToMgaPath(const CString& connStr) {
+	ASSERT(connStr.Left(4).CompareNoCase(_T("MGA=")) == 0);
+	return connStr.Right(connStr.GetLength() - 4);
+}
+
+
 // --------------------------- Error
 
 void DisplayError(const TCHAR *msg, HRESULT hr) NOTHROW;

Modified: trunk/GME/GMEActiveBrowser/ActiveBrowserPropertyPage.cpp
==============================================================================
--- trunk/GME/GMEActiveBrowser/ActiveBrowserPropertyPage.cpp	Tue May 31 17:00:25 2011	(r1332)
+++ trunk/GME/GMEActiveBrowser/ActiveBrowserPropertyPage.cpp	Wed Jun  1 14:54:04 2011	(r1333)
@@ -1548,11 +1548,8 @@
 		}
 		else // MGA is presumed in this case
 		{
-			// add extension
-			if( dlg.m_strConnString.Find( _T(".")) == -1) dlg.m_strConnString += _T(".mga");  
-
-			// add the 'MGA=' prefix
-			if( dlg.m_strConnString.Left(4) != _T("MGA=")) dlg.m_strConnString.Insert(0, _T("MGA="));
+			if (dlg.relativePath != "")
+				dlg.m_strConnString = dlg.relativePath;
 		}
 
 		MSGTRY {
@@ -1661,7 +1658,11 @@
 				pMgaContext->BeginTransaction(false);
 					
 				long errs;
-				COMTHROW(ccpFolder->RefreshLibraryV3( CComBSTR( dlg.m_strConnString), dlg.m_bOptimized, &errs) );
+				if (dlg.relativePath != "") {
+					COMTHROW(ccpFolder->RefreshLibraryV3( CComBSTR( dlg.relativePath), dlg.m_bOptimized, &errs) );
+				} else {
+					COMTHROW(ccpFolder->RefreshLibraryV3( CComBSTR( dlg.m_strConnString), dlg.m_bOptimized, &errs) );
+				}
 				ccpFolder.Release();
 				pMgaContext->CommitTransaction();
 			}

Modified: trunk/GME/GMEActiveBrowser/AttachLibDlg.cpp
==============================================================================
--- trunk/GME/GMEActiveBrowser/AttachLibDlg.cpp	Tue May 31 17:00:25 2011	(r1332)
+++ trunk/GME/GMEActiveBrowser/AttachLibDlg.cpp	Wed Jun  1 14:54:04 2011	(r1333)
@@ -25,6 +25,7 @@
 	//{{AFX_DATA_INIT(CAttachLibDlg)
 	m_strConnString = _T("");
 	m_bOptimized = FALSE;
+	m_bRelativePath = TRUE;
 	//}}AFX_DATA_INIT
 }
 
@@ -35,6 +36,7 @@
 	//{{AFX_DATA_MAP(CAttachLibDlg)
 	DDX_Text(pDX, IDC_CONN_STRING, m_strConnString);
 	DDX_Check(pDX, IDC_CHECKOPTIMIZED, m_bOptimized);
+	DDX_Check(pDX, IDC_CHECK_RELATIVE_PATH, m_bRelativePath);
 	//}}AFX_DATA_MAP
 }
 
@@ -51,27 +53,40 @@
 void CAttachLibDlg::OnOK() 
 {
 
-	if(!UpdateData(TRUE))return;
+	if(!UpdateData(TRUE)) return;
 	CDialog::OnOK();
+	
+	if (m_strConnString.Right(3).CompareNoCase(_T("mga")) == 0) {
+		CString mgaPath = m_strConnString;
+		if (m_strConnString.Left(4).CompareNoCase(_T("MGA=")) == 0) {
+			mgaPath = m_strConnString.Right(m_strConnString.GetLength() - 4);
+		}
+		if (m_bRelativePath) {
+			if (PathRelativePathTo(relativePath.GetBuffer(MAX_PATH), currentMgaPath, FILE_ATTRIBUTE_DIRECTORY, 
+				mgaPath, FILE_ATTRIBUTE_NORMAL)) {
+				relativePath.ReleaseBuffer();
+			} else {
+				relativePath.ReleaseBufferSetLength(0);
+			}
+		} else {
+			CString filename, dirname;
+			GetFullPathName(mgaPath, filename, dirname);
+			if (filename != "")
+				m_strConnString = _T("MGA=") + dirname + _T("\\") + filename;
+		}
+	}
 }
 
 void CAttachLibDlg::OnBrowse() 
 {
+	UpdateData(TRUE);
 
 	static TCHAR BASED_CODE szFilter[] = _T("Binary Project Files (*.mga)|*.mga|Multiuser Project Files (*.mgx)|*.mgx|All Files (*.*)|*.*||");
 
 	CFileDialog dlg(TRUE,_T("mga"),NULL,NULL,szFilter, this);
-	TCHAR currentMgaPath[MAX_PATH];
-	if (m_strParentConnection.GetLength() > 4 && m_strParentConnection.Left(4) == "MGA=") {
-		const TCHAR* zsConn = m_strParentConnection;
-		zsConn += 4; // skip MGA=
-		TCHAR* filename;
-		if (!GetFullPathName(zsConn, MAX_PATH, currentMgaPath, &filename) || filename == 0) {
-		} else {
-			*filename = _T('\0');
-			dlg.GetOFN().lpstrInitialDir = currentMgaPath;
-		}
-	}
+
+	if (currentMgaPath != "")
+		dlg.GetOFN().lpstrInitialDir = currentMgaPath;
 
 	if(dlg.DoModal()!=IDOK) return;
 
@@ -119,6 +134,17 @@
 		ptr->SetWindowText( (LPCTSTR) hint);
 	}
 
+	if (m_strParentConnection.GetLength() > 4 && m_strParentConnection.Left(4) == "MGA=") {
+		const TCHAR* zsConn = m_strParentConnection;
+		zsConn += 4; // skip MGA=
+		TCHAR* filename;
+		if (!GetFullPathName(zsConn, MAX_PATH, currentMgaPath.GetBuffer(MAX_PATH), &filename) || filename == 0) {
+		} else {
+			*filename = _T('\0');
+		}
+		currentMgaPath.ReleaseBuffer();
+	}
+
 	CDialog::OnInitDialog();
 	
 	SetWindowText(m_strCaption);

Modified: trunk/GME/GMEActiveBrowser/AttachLibDlg.h
==============================================================================
--- trunk/GME/GMEActiveBrowser/AttachLibDlg.h	Tue May 31 17:00:25 2011	(r1332)
+++ trunk/GME/GMEActiveBrowser/AttachLibDlg.h	Wed Jun  1 14:54:04 2011	(r1333)
@@ -16,6 +16,8 @@
 public:
 	CString m_strCaption;
 	CString m_strParentConnection;
+	CString relativePath;
+	CString currentMgaPath;
 	CAttachLibDlg(CWnd* pParent = NULL);   // standard constructor
 
 // Dialog Data
@@ -23,6 +25,7 @@
 	enum { IDD = IDD_ATTACH_LIB_DIALOG };
 	CString	m_strConnString;
 	BOOL    m_bOptimized;
+	BOOL    m_bRelativePath;
 	//}}AFX_DATA
 
 

Modified: trunk/GME/GMEActiveBrowser/GMEActiveBrowser.rc
==============================================================================
--- trunk/GME/GMEActiveBrowser/GMEActiveBrowser.rc	Tue May 31 17:00:25 2011	(r1332)
+++ trunk/GME/GMEActiveBrowser/GMEActiveBrowser.rc	Wed Jun  1 14:54:04 2011	(r1333)
@@ -177,10 +177,11 @@
     PUSHBUTTON      "...",IDC_BROWSE,342,20,14,14
     CONTROL         "Optimize (Ungroup Inner Libraries)",IDC_CHECKOPTIMIZED,
                     "Button",BS_AUTOCHECKBOX | WS_TABSTOP,38,36,122,12
+    CONTROL         "Use Relative Path",IDC_CHECK_RELATIVE_PATH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,163,38,73,10
     DEFPUSHBUTTON   "OK",IDOK,111,53,50,14
     PUSHBUTTON      "Cancel",IDCANCEL,204,53,50,14
     LTEXT           "Mga Connection String:",IDC_CONNSTR,37,9,319,8,SS_ENDELLIPSIS
-    ICON            IDI_LIBRARY,IDC_STATIC,8,12,21,20
+    ICON            IDI_LIBRARY,IDC_STATIC,8,12,20,20
 END
 
 

Modified: trunk/GME/GMEActiveBrowser/resource.h
==============================================================================
--- trunk/GME/GMEActiveBrowser/resource.h	Tue May 31 17:00:25 2011	(r1332)
+++ trunk/GME/GMEActiveBrowser/resource.h	Wed Jun  1 14:54:04 2011	(r1333)
@@ -40,6 +40,7 @@
 #define IDI_LIBRARY                     218
 #define IDC_CONNSTR                     220
 #define IDC_TAB1                        221
+#define IDC_CHECK_RELATIVE_PATH         222
 #define IDC_COMBO_SEARCH_AGGREGATE      1001
 #define IDC_TREE_INHERITANCE            1002
 #define IDC_TREE_AGGREGATE              1002
@@ -91,7 +92,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        220
 #define _APS_NEXT_COMMAND_VALUE         32813
-#define _APS_NEXT_CONTROL_VALUE         222
+#define _APS_NEXT_CONTROL_VALUE         223
 #define _APS_NEXT_SYMED_VALUE           104
 #endif
 #endif

Modified: trunk/GME/Gme/MgaOpenDlg.cpp
==============================================================================
--- trunk/GME/Gme/MgaOpenDlg.cpp	Tue May 31 17:00:25 2011	(r1332)
+++ trunk/GME/Gme/MgaOpenDlg.cpp	Wed Jun  1 14:54:04 2011	(r1333)
@@ -109,31 +109,19 @@
 		filters.Insert( 0, spec_filter);
 	}
 
-	const TCHAR* initialFile = NULL; // NULL or points into currentMgaPath
-	TCHAR currentMgaPath[MAX_PATH];
-	if (theApp.isMgaProj()) {
-		CString conn = theApp.connString();
-		const TCHAR* zsConn = conn;
-		zsConn += 4; // skip MGA=
-		TCHAR* filename;
-		if (!GetFullPathName(zsConn, MAX_PATH, currentMgaPath, &filename) || filename == 0) {
-		} else {
-			initialFile = filename;
-		}
+	CString file, dir;
+	if (theApp.isMgaProj() && theApp.mgaProject)
+	{
+		theApp.getMgaPaths(file, dir);
 	}
 
 	CString conn;
-	CFileDialog dlg(flag_isopen ? TRUE : FALSE, NULL, initialFile, 
+	CFileDialog dlg(flag_isopen ? TRUE : FALSE, NULL, (file == _T("")) ? NULL : (LPCTSTR)file, 
 			OFN_EXPLORER | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | 
 			0, filters);
 
-	CString file, dir;
-	if (theApp.isMgaProj() && theApp.mgaProject)
-	{
-		theApp.getMgaPaths(file, dir);
-		if (dir != L"")
-			dlg.GetOFN().lpstrInitialDir = dir;
-	}
+	if (dir != _T(""))
+		dlg.GetOFN().lpstrInitialDir = dir;
 
 	if( dlg.DoModal() == IDOK )	{
 		conn = CString(_T("MGA=")) + dlg.GetPathName();

Modified: trunk/GME/Mga/MgaLibOps.cpp
==============================================================================
--- trunk/GME/Mga/MgaLibOps.cpp	Tue May 31 17:00:25 2011	(r1332)
+++ trunk/GME/Mga/MgaLibOps.cpp	Wed Jun  1 14:54:04 2011	(r1333)
@@ -12,6 +12,27 @@
 /*static*/ const wchar_t* Ozer::StorageMgr::INCLUDES_STR        = L"_includes";
 /*static*/ const wchar_t* Ozer::StorageMgr::INCLUDED_BY_STR     = L"_includedBy";
 
+std::wstring getConnStrForLibName(FCO* fco, const TCHAR* libname) {
+	std::wstring connStr = libname;
+	if (_tcsnicmp(connStr.c_str(), _T("MGA="), 4) != 0 && _tcsnicmp(connStr.c_str(), _T("MGX="), 4) != 0) {
+		CComPtr<IMgaProject> project;
+		COMTHROW(fco->get_Project(&project));
+		_bstr_t bconnStr;
+		COMTHROW(project->get_ProjectConnStr(bconnStr.GetAddress()));
+
+		TCHAR currentMgaPath[MAX_PATH];
+		TCHAR* tcfilename;
+		if (!GetFullPathName(static_cast<const TCHAR*>(bconnStr)+4, MAX_PATH, currentMgaPath, &tcfilename) || tcfilename == 0) {
+		} else {
+			*(tcfilename-1) = '\0';
+			TCHAR combined[MAX_PATH];
+			PathCombine(combined, currentMgaPath, connStr.c_str());
+			connStr = std::wstring(_T("MGA=")) + combined;
+		}
+	}
+	return connStr;
+}
+
 HRESULT FCO::get_LibraryName(BSTR *libname) {
 	COMTRY {
 		CHECK_OUTSTRPAR(libname);
@@ -334,7 +355,7 @@
 	} MGACOLL_ITERATE_END;
 }
 									   
-void CreateLibraryImage(CMgaProject *mgaproject, LibWorker& lw, CoreObj &libimgroot, bool p_tolerateOldMga, bool *p_ptrIsOldMga, Typedefs::LIBMAP& p_results, Typedefs::LIBVEC& p_dependentLibs, CComBSTR& p_infoMsg) {
+void CreateLibraryImage(CMgaProject *mgaproject, LibWorker& lw, CoreObj &libimgroot, bool p_tolerateOldMga, bool *p_ptrIsOldMga, Typedefs::LIBMAP& p_results, Typedefs::LIBVEC& p_dependentLibs, CComBSTR& p_infoMsg, const CComBSTR& libname) {
 	CComBSTR connstr = lw.getExpandedConnectionStr();
 	CComPtr<IMgaProject> p;
 	PointerFixup fixup;
@@ -503,7 +524,7 @@
 			LibImgHelper::deleteSuperfluousLibs( superfluous_libs, reporter);
 		}
 
-		libimgroot[ATTRID_NAME] = lw.getConnectionStr();
+		libimgroot[ATTRID_NAME] = libname;
 		libimgroot[ATTRID_PERMISSIONS] = LIBROOT_FLAG;
 		
 		//*************************************************
@@ -544,7 +565,8 @@
 
 		// 'self' here is the rootfolder of the project
 		Typedefs::LIBMAP top_libs;
-		LibWorker lw( mgaproject, libname, ungroup == VARIANT_TRUE);
+
+		LibWorker lw( mgaproject, CComBSTR(getConnStrForLibName(this, libname).c_str()), ungroup == VARIANT_TRUE);
 		SearchTool::m_optimized = lw.isOptimized();
 		LibImgHelper::recordLibs( false, self, top_libs); // consider existing toplibs only (self = project)
 		
@@ -562,7 +584,7 @@
 		bool is_old_lib( false);
 		Typedefs::LIBVEC dep_libs; // those libraries which are factored out
 		CComBSTR infmsg; // informative message about the lib pairs found
-		CreateLibraryImage(mgaproject, lw, libimgroot, accept_old_lib, &is_old_lib, top_libs, dep_libs, infmsg);
+		CreateLibraryImage(mgaproject, lw, libimgroot, accept_old_lib, &is_old_lib, top_libs, dep_libs, infmsg, CComBSTR(libname));
 		if( lw.isOptimized() && infmsg && infmsg.Length() > 0) // informative message about possible guid duplications in the library
 			reporter.show( infmsg, false);
 
@@ -724,8 +746,6 @@
 	}
 }
 
-
-
 HRESULT FCO::doRefresh( BSTR libname, VARIANT_BOOL ungroup, long *ptrNumOfErrors) {
 	long placeholder;
 	if( !ptrNumOfErrors) // invalid ptr
@@ -746,7 +766,8 @@
 				COMTHROW(E_MGA_OP_REFUSED);
 			}
 
-			LibWorker lw( mgaproject, libname, ungroup  == VARIANT_TRUE);
+			std::wstring connStr = getConnStrForLibName(this, libname).c_str();
+			LibWorker lw( mgaproject, CComBSTR(connStr.c_str()), ungroup  == VARIANT_TRUE);
 			SearchTool::m_optimized = lw.isOptimized();
 
 			// examining toplevel libraries in project
@@ -822,7 +843,7 @@
 			bool is_old_lib_copy( false);
 			Typedefs::LIBVEC dep_libs; // those libraries which are factored out
 			CComBSTR infmsg;
-			CreateLibraryImage(mgaproject, lw, libimgroot, accept_old_lib, &is_old_lib_copy, lib_results, dep_libs, infmsg);
+			CreateLibraryImage(mgaproject, lw, libimgroot, accept_old_lib, &is_old_lib_copy, lib_results, dep_libs, infmsg, CComBSTR(libname));
 			if( lw.isOptimized() && infmsg && infmsg.Length() > 0) // informative message about possible guid duplications in the library
 				reporter.show( infmsg, false);
 	 


More information about the gme-commit mailing list