⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resorgsymbolsdocmultifile.cpp

📁 ResOrg 图形化管理Vc项目的资源ID的工具的源代码。 ResOrg - Manage and Renumber Resource Symbol IDs Introduction The
💻 CPP
📖 第 1 页 / 共 2 页
字号:


bool CResOrgSymbolsDocMultiFile::AddFiles(const CStringArray& arraySymbolFilePathNames)
{
	ASSERT(NULL != m_pSymbolManager);

	bool bResult = false;

	if ( (NULL != m_pSymbolManager) && (arraySymbolFilePathNames.GetSize() > 0) )
	{	
		CResOrgProgressDlg dlg;

		dlg.Initialise( _T("Open Projects"), arraySymbolFilePathNames.GetSize());
		dlg.Create();

		for (int n = 0; n < arraySymbolFilePathNames.GetSize(); n++)
		{
			CString sPathName = arraySymbolFilePathNames[n];


			if (!sPathName.IsEmpty() )
			{
				CString sCompactedPath;

				LPTSTR pszCompactedPath = sCompactedPath.GetBuffer(_MAX_PATH);

				VERIFY(::PathCompactPathEx(	pszCompactedPath,
											sPathName,
											40,
											0) );

				sCompactedPath.ReleaseBuffer();

				CString sMsg;
				sMsg.Format( _T("Opening <b>%s</b> "), sCompactedPath);

				dlg.SetMessage(sMsg);

				if (NULL != static_cast<CResourceSymbolManagerMultiFile*>(m_pSymbolManager)->AddSymbolFile(sPathName) )
				{
					bResult = true;
				}
			}
		}
		if (bResult)
		{
			m_pSymbolManager->SortByValue();

			m_pSymbolManager->CountConflicts();

			UpdateAllViews(NULL, SYM_REFRESH);
		}
		dlg.DestroyWindow();
	}
	return bResult;
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgSymbolsDocMultiFile implementation

bool CResOrgSymbolsDocMultiFile::CreateSymbolManager(void)
{
	if (NULL == m_pSymbolManager)
	{
		m_pSymbolManager = new CResourceSymbolManagerMultiFile;

		return (NULL != m_pSymbolManager);
	}
	return false;
}


bool CResOrgSymbolsDocMultiFile::StartFileChangeMonitor(const CString& sPathName)
{
	UNREFERENCED_PARAMETER(sPathName);

/*	if (!m_FileChangeMonitor.IsMonitoring())
	{
		POSITION pos = GetFirstViewPosition();
		if (pos != NULL)
		{
			CView* pView = GetNextView(pos);

			return m_FileChangeMonitor.Start(	sPathName,
												pView,
												WM_COMMAND,
												ID_FILE_CHANGED,
												THREAD_PRIORITY_LOWEST);
		}
	}
*/
	return false;
}


bool CResOrgSymbolsDocMultiFile::StopFileChangeMonitor(void)
{
//	if (m_FileChangeMonitor.IsMonitoring())
//	{
//		return m_FileChangeMonitor.Stop();
//	}
	return false;
}


// TODO: Move this to the ResOrgCore namespace as a helper function
// (CResOrgNETAddInToolWinFormView has the same code!)
bool CResOrgSymbolsDocMultiFile::Save(CResourceSymbolManager* pSymbols)
{
	bool bResult = false;

	CString sPathName = pSymbols->GetPathName();
	if (!sPathName.IsEmpty() )
	{
		DWORD dwAttrib = ::GetFileAttributes(sPathName);
		if (::FileExists(sPathName) && (dwAttrib & FILE_ATTRIBUTE_READONLY) )
		{
			UINT eResult = ::DoOverwritePrompt(sPathName);
			switch (eResult)
			{
			case IDYES:
				if (!::SetFileAttributes(sPathName, dwAttrib & ~FILE_ATTRIBUTE_READONLY) )
				{
					::AfxMessageBox(IDP_SYM_FILE_ERR_FILE_ATTRIBUTES, MB_OK | MB_ICONSTOP);

					return false;
				}
				break;

			case IDNO:
				{
					CFileDialog dlg(FALSE,									// Save As
									CString( (LPCTSTR)IDS_FILE_FILTER_RESOURCE_SYMBOL_FILES_EXT),
																			// Default extension
									NULL,									// Default filename
									OFN_PATHMUSTEXIST | OFN_ENABLESIZING,	// Flags
									CString( (LPCTSTR)IDS_FILE_FILTER_RESOURCE_SYMBOL_FILES),
																			// File filter
									::AfxGetMainWnd() );					// Parent window

					if (IDOK != dlg.DoModal())
					{
						return false;
					}
					sPathName = dlg.GetPathName();
				}
				break;

			case IDCANCEL:
				return false;

			default:
				ASSERT(FALSE);
				break;
			}
		}

		try
		{
			// Save the file to disk
			CStdioFile f(	sPathName,
							CFile::modeWrite | CFile::modeCreate | CFile::shareDenyWrite);

			// File opened OK
			//
			// Now create an archive, and an empty text buffer
			CArchive ar(&f, CArchive::store);

			pSymbols->Serialize(ar);

			ar.Flush();
			ar.Close();
			f.Flush();
			f.Close();

			bResult = true;
		}
		catch (CException* e)
		{
			TCHAR szCause[_MAX_PATH];
			e->GetErrorMessage(szCause, _MAX_PATH);
			CString sMsg;

			sMsg.Format(IDP_SYM_FILE_ERR_SAVE_FILE, szCause);

			TRACE1("%s\n", sMsg);
			::AfxMessageBox(sMsg, MB_OK | MB_ICONSTOP);

			e->Delete();
		}
	}
	return bResult;
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgSymbolsDocMultiFile message handlers

void CResOrgSymbolsDocMultiFile::OnCmdFileChanged(void)
{
/*
	CString sPathName = GetPathName();

	CNGSplitPath split(sPathName);
	CString sFileName = split.GetFileName() + split.GetExtension();

	BOOL bModified	= IsModified();
	BOOL bPrompt	= bModified || !Options.AutoReloadFiles();
	BOOL bReload	= !bModified && Options.AutoReloadFiles();

	if (bPrompt)
	{
		CNGMessageBox dlg;

		dlg.FormatMsgEx(MAKEINTRESOURCE( bModified ? IDP_SYM_FILE_CHANGED_EX : IDP_SYM_FILE_CHANGED),
						_T("RTF"),
						sFileName);
		dlg.SetRtf();
		dlg.SetStandardIcon(IDI_WARNING);
		dlg.AddButton(IDYES, FALSE, FALSE, _T("&Yes") );
		dlg.AddButton(IDNO, TRUE, TRUE, _T("&No") );

		bReload =  (IDYES == dlg.DoModal() );
	}

	if (bReload)
	{
		OnOpenDocument(sPathName);
		UpdateAllViews(NULL, SYM_REFRESH);
	}
	else
	{
		StartFileChangeMonitor(sPathName);
	}
*/
}


void CResOrgSymbolsDocMultiFile::OnFileSave(void)
{
//	StopFileChangeMonitor();

	if (NULL != m_pSymbolManager)
	{
		CStringArray arrayPathNames;
		GetMultiFileSymbolManager()->GetSymbolFilePathNames(arrayPathNames);

		CStringArray arrayFailedSaves;

		for (int n = 0; n < arrayPathNames.GetSize(); n++)
		{
			CString sPathName = arrayPathNames[n];
			if (!sPathName.IsEmpty() )
			{
				CResourceSymbolManager* pMngr = GetMultiFileSymbolManager()->GetSymbolManager(sPathName);
				if ( (NULL != pMngr) && pMngr->IsModified() )
				{
					if (Save(pMngr) )
					{
						pMngr->SetModifiedFlag(false);
					}
					else
					{
						// We'll probably use this later
						arrayFailedSaves.Add(pMngr->GetPathName() );
					}
				}
			}
		}
		bool bModified = (arrayFailedSaves.GetSize() > 0);

		SetModifiedFlag(bModified);

		m_pSymbolManager->SetModifiedFlag(bModified);		// This really should be linked to the document...
	}
}


void CResOrgSymbolsDocMultiFile::OnUpdateFileSave(CCmdUI* pCmdUI)
{
	BOOL bEnable = FALSE;

	if (NULL != GetMultiFileSymbolManager() )
	{
		bEnable = (GetMultiFileSymbolManager()->GetSymbolFileCount() > 0);
	}
	pCmdUI->Enable(bEnable);
}


void CResOrgSymbolsDocMultiFile::OnUpdateFileSaveAs(CCmdUI* pCmdUI)
{
	pCmdUI->Enable(FALSE);
}


// Renumber all symbols
void CResOrgSymbolsDocMultiFile::OnCmdRenumberSymbols(void) 
{
/*	// To renumber all the symbols in a given file we need to pick starting
	// values for each of the four symbol catgories identified by the _APS_NEXT...
	// symbols in each resource file.
	//
	// The Symbol Renumbering Wizard works this out by looking at the values
	// of existing symbols in the resource symbol file.
	//
	CRenumWizard Wizard;
	Wizard.Initialise(m_pSymbolManager);

	if (ID_WIZFINISH == Wizard.DoModal() )
	{
		if (m_pSymbolManager->IsModified() )
		{
			SetModifiedFlag(TRUE);
			UpdateAllViews(NULL, SYM_REFRESH);
		}
	}
*/
}


void CResOrgSymbolsDocMultiFile::OnUpdateRenumberSymbols(CCmdUI* pCmdUI)
{
//	pCmdUI->Enable(m_pSymbolManager->GetSymbolCount() > 0);
	pCmdUI->Enable(FALSE);		// Temporary
}


void CResOrgSymbolsDocMultiFile::OnCmdFileProperties(void) 
{
	CResourceSymbolFilePropertySheet dlg(IDP_SYM_FILE_PROPERTIES_CAPTION, ::AfxGetMainWnd() );

	dlg.Initialise(m_pSymbolManager, this);

	dlg.DoModal();

	if (m_pSymbolManager->IsModified() )
	{
		CStringArray arrayPathNames;
		GetMultiFileSymbolManager()->GetSymbolFilePathNames(arrayPathNames);
			
		SetTitle( GetDisplayTitle(arrayPathNames) );

		SetModifiedFlag(TRUE);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -