Esempio n. 1
0
CDocTemplate::Confidence CDocTemplate::MatchDocType(LPCTSTR lpszPathName,
	CDocument*& rpDocMatch)
{
	ASSERT(lpszPathName != NULL);
	rpDocMatch = NULL;

	// go through all documents
	POSITION pos = GetFirstDocPosition();
	while (pos != NULL)
	{
		CDocument* pDoc = GetNextDoc(pos);
		if (AfxComparePath(pDoc->GetPathName(), lpszPathName))
		{
			// already open
			rpDocMatch = pDoc;
			return yesAlreadyOpen;
		}
	}

	// see if it matches our default suffix
	CString strFilterExt;
	if (GetDocString(strFilterExt, CDocTemplate::filterExt) &&
	  !strFilterExt.IsEmpty())
	{
		// see if extension matches
		ASSERT(strFilterExt[0] == '.');
		LPCTSTR lpszDot = _tcsrchr(lpszPathName, '.');
		if (lpszDot != NULL && lstrcmpi(lpszDot, strFilterExt) == 0)
			return yesAttemptNative; // extension matches, looks like ours
	}

	// otherwise we will guess it may work
	return yesAttemptForeign;
}
Esempio n. 2
0
// Make sure the first entries in our vector match the filenames in the MFC string array
bool CHexFileList::Check()
{
	for (int ii = 0; ii < m_nSize-1 && int(name_.size())-ii-1 > 0; ++ii)
		if (!AfxComparePath(m_arrNames[ii], name_[name_.size()-ii-1]))
		{
			TRACE2("Recent File List ERROR: <%s> does not match <%s>", m_arrNames[ii], name_[name_.size()-ii-1]);
			return false;
		}
	return true;
}
Esempio n. 3
0
void CHexFileList::Add(LPCTSTR lpszPathName)
{
	ASSERT(lpszPathName != NULL);
	ASSERT(AfxIsValidString(lpszPathName));

	// Get the fully qualified path name
	TCHAR szTemp[_MAX_PATH];
	AfxFullPath(szTemp, lpszPathName);

	ASSERT(hash_.size() == name_.size());
	ASSERT(opened_.size() == name_.size());
	ASSERT(data_.size() == name_.size());

	CString saved_data;

	// Find and remove any existing entry(s) for this file
	// Note: we use an index rather than iterator since an iterator is invalid after erase() is called
	for (int ii = name_.size()-1; ii >= 0; ii--)
	{
//        if (_stricmp(name_[ii], szTemp) == 0)
		if (AfxComparePath(name_[ii], szTemp))     // Handle DBCS case-insensitive comparisons etc
		{
			// Remove the existing entry for the file
			name_.erase(name_.begin() + ii);
			hash_.erase(hash_.begin() + ii);
			opened_.erase(opened_.begin() + ii);
			saved_data = data_[ii];                //  save data_ for when file read (below)
			data_.erase(data_.begin() + ii);
		}
	}

	// Add to the end of the vectors (most recent files at end)
	CString ss(szTemp);
	name_.push_back(ss);
	ss.MakeUpper();
	hash_.push_back(str_hash(ss));
	opened_.push_back(time(NULL));
	data_.push_back(saved_data);

	ASSERT(hash_.size() == name_.size());
	ASSERT(opened_.size() == name_.size());
	ASSERT(data_.size() == name_.size());

	// Let base class also keep its silly little list
	CRecentFileList::Add(lpszPathName);

	((CMainFrame *)AfxGetMainWnd())->UpdateExplorer(szTemp);  // Let explorer update (last opened time)
	ASSERT(Check());
}
Esempio n. 4
0
int CHexFileList::GetIndex(LPCTSTR lpszPathName) const
{
	ASSERT(lpszPathName != NULL);
	ASSERT(AfxIsValidString(lpszPathName));

	CString ss(lpszPathName);
	ss.MakeUpper();
	unsigned long hash = str_hash(ss);
	for (int ii = 0; ii < name_.size(); ++ii)
	{
		if (hash == hash_[ii] && AfxComparePath(name_[ii], lpszPathName))
			return ii;
	}

	return -1;
}
Esempio n. 5
0
bool DjVuSource::SaveAs(const CString& strFileName)
{
	if (AfxComparePath(strFileName, m_strFileName))
		return false;

	try
	{
		m_pDjVuDoc->wait_for_complete_init();
		GURL url = GURL::Filename::UTF8(MakeUTF8String(strFileName));

		// Close open files for this url
		DataPool::load_file(url);

		if (!CopyFile(m_strFileName, strFileName, false))
			return false;
	}
	catch (GException&)
	{
		return false;
	}

	return true;
}
Esempio n. 6
0
void CHexFileList::Add(LPCTSTR lpszPathName)
{
	ASSERT(lpszPathName != NULL);
	ASSERT(AfxIsValidString(lpszPathName));

	// Get the fully qualified path name
	TCHAR szTemp[_MAX_PATH];
	AfxFullPath(szTemp, lpszPathName);

	ASSERT(hash_.size() == name_.size());
	ASSERT(opened_.size() == name_.size());
	ASSERT(open_count_.size() == name_.size());
	ASSERT(data_.size() == name_.size());

	CString saved_data;

	// Get hash to speed search of the list
	CString ss(szTemp);
	ss.MakeUpper();
	unsigned long hash = str_hash(ss);

	int open_count = 0;

	// Find and remove any existing entry(s) for this file
	// Note: we use an index rather than iterator since an iterator is invalid after erase() is called
	for (int ii = name_.size()-1; ii >= 0; ii--)
	{
		// Using AfxComparePath is more reliable as it handles DBCS case-insensitive comparisons etc
		if (hash == hash_[ii] && AfxComparePath(name_[ii], szTemp))
		{
			// Remove the existing entry for the file
			name_.erase(name_.begin() + ii);
			hash_.erase(hash_.begin() + ii);
			opened_.erase(opened_.begin() + ii);
			open_count = open_count_[ii];          // save open count
			open_count_.erase(open_count_.begin() + ii);
			saved_data = data_[ii];                //  save data_ for when file read (below)
			data_.erase(data_.begin() + ii);

			break;   // A file should only appear in the list once (but we should have a way to remove duplicates?)
		}
	}

	// Add to the end of the vectors (so most recent files are at the end)
	name_.push_back(szTemp);
	hash_.push_back(hash);
	opened_.push_back(time(NULL));
	open_count_.push_back(open_count + 1);  // inc open count (do we need IncOpenCount()?)
	data_.push_back(saved_data);

	ASSERT(hash_.size() == name_.size());
	ASSERT(opened_.size() == name_.size());
	ASSERT(open_count_.size() == name_.size());
	ASSERT(data_.size() == name_.size());

	// Let base class also keep its silly little list
	CRecentFileList::Add(lpszPathName);

	((CMainFrame *)AfxGetMainWnd())->UpdateExplorer(szTemp);  // Let explorer update (last opened time)
	ASSERT(Check());
}
Esempio n. 7
0
BOOL COleDocument::OnSaveDocument(LPCTSTR lpszPathName)
	// lpszPathName must be fully qualified
{
	ASSERT(lpszPathName == NULL || AfxIsValidString(lpszPathName));

	// use default implementation if 'docfile' not enabled
	if (!m_bCompoundFile && m_lpRootStg == NULL)
	{
		ASSERT(lpszPathName != NULL);
		return CDocument::OnSaveDocument(lpszPathName);
	}

	LPSTORAGE lpOrigStg = NULL;
	if (lpszPathName != NULL)
		m_bSameAsLoad = AfxComparePath(m_strPathName, lpszPathName);

	BOOL bResult = FALSE;
	TRY
	{
		// open new root storage if necessary
		if (lpszPathName != NULL && !m_bSameAsLoad)
		{
			// temporarily detach current storage
			lpOrigStg = m_lpRootStg;
			m_lpRootStg = NULL;

			LPSTORAGE lpStorage;
			const CStringW strPathName(lpszPathName);
			SCODE sc = ::StgCreateDocfile(strPathName.GetString(),
				STGM_READWRITE|STGM_TRANSACTED|STGM_SHARE_DENY_WRITE|STGM_CREATE,
				0, &lpStorage);
			if (sc != S_OK)
				AfxThrowOleException(sc);

			ASSERT(lpStorage != NULL);
			m_lpRootStg = lpStorage;
		}
		ASSERT(m_lpRootStg != NULL);

		// use helper to save to root storage
		SaveToStorage();

		if (lpszPathName != NULL)
		{
			// commit each of the items
			CommitItems(m_bRemember && !m_bSameAsLoad);

			// mark document as clean if remembering the storage
			if (m_bRemember)
				SetModifiedFlag(FALSE);

			// remember correct storage or release save copy as storage
			if (!m_bSameAsLoad)
			{
				if (m_bRemember)
				{
					// Save As case -- m_stgRoot is new storage, forget old storage
					lpOrigStg->Release();
				}
				else
				{
					// Save Copy As case -- m_stgRoot should hook up to m_stgOrig.
					m_lpRootStg->Release();
					m_lpRootStg = lpOrigStg;
				}
			}
		}

		bResult = TRUE;
	}
	CATCH_ALL(e)
	{
		if (lpOrigStg != NULL)
		{
			// save as failed: abort new storage, and re-attach original
			RELEASE(m_lpRootStg);
			m_lpRootStg = lpOrigStg;
		}

		if (lpszPathName == NULL)
		{
			THROW_LAST();
		}

		TRY
		{
			ReportSaveLoadException(lpszPathName, e,
				TRUE, AFX_IDP_FAILED_TO_SAVE_DOC);
		}
		END_TRY
		DELETE_EXCEPTION(e);
	}
	END_CATCH_ALL

	// cleanup
	m_bSameAsLoad = TRUE;
	m_bRemember = TRUE;

	return bResult;
}
CXTPRecentFileListItem* CXTPRecentFileList::AddItem(LPCTSTR lpszPathName)
{
	ASSERT(m_arrNames != NULL);
	ASSERT(lpszPathName != NULL);
	ASSERT(AfxIsValidString(lpszPathName));

	// fully qualify the path name
	TCHAR szTemp[_MAX_PATH];
	AfxFullPath(szTemp, lpszPathName);

	int iMRU = 0;
	CXTPRecentFileListItem* pItem = NULL;

	// update the MRU list, if an existing MRU string matches file name
	for (; iMRU < m_nSize - 1; iMRU++)
	{
		if (AfxComparePath(m_arrNames[iMRU], szTemp))
		{
			pItem = m_pItems[iMRU];
			break;      // iMRU will point to matching entry
		}
	}

	if (iMRU == m_nSize - 1) // Not found
	{
		for (; iMRU >= 0; iMRU--)
		{
			if (!m_pItems[iMRU] || !m_pItems[iMRU]->IsPinned())
				break;
		}
	}

	if (iMRU < 0)
		return NULL;

	if (pItem == NULL && m_pItems[iMRU] != NULL)
	{
		CMDTARGET_RELEASE(m_pItems[iMRU]);
	}

	// move MRU strings before this one down
	for (; iMRU > 0; iMRU--)
	{
		ASSERT(iMRU > 0);
		ASSERT(iMRU < m_nSize);
		m_arrNames[iMRU] = m_arrNames[iMRU - 1];
		m_pItems[iMRU] = m_pItems[iMRU - 1];
	}
	// place this one at the beginning
	m_arrNames[0] = szTemp;

	if (pItem)
	{
		m_pItems[0] = pItem;
	}
	else
	{
		pItem = new CXTPRecentFileListItem(this);
		pItem->m_strPathName = m_arrNames[0];

		m_pItems[0] = pItem;

		OnNewItem(pItem);
	}
	return pItem;
}