void CProfile::Init() { // Keep track whether the profile was changed. m_bNeedsSave = false; CFile file; // Load the profile array from the storage file. if(!file.Open(m_strDataFileName, CFile::modeRead)) { // File didn't open properly so just set the filename. // we will create a new file later at destruction time. m_strDataFullPath = file.GetFilePath(); } else { // Open the existing file and read in the data. m_strDataFullPath = file.GetFilePath(); for(int i=0; i<TABLE_SIZE; ++i) { _ReadElement(file, m_ProfileTable[i].strSection, m_ProfileTable[i].strEntry, m_ProfileTable[i].strValue); } file.Close(); } }
void CResourceListDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // There is nothing to save. int x = 0; } else { CFile *pFile = ar.GetFile(); // Set the current directory, so we know where to look for the resource files. // If not, clicking on an item in the recent documents list won't work CString path = pFile->GetFilePath(); path.MakeLower(); int iFileOffset = path.Find(TEXT("\\resource.map")); if (iFileOffset > 0) { path.SetAt(iFileOffset, 0); // Null terminate it // Set this folder as our new game folder CResourceMap &map = theApp.GetResourceMap(); map.SetGameFolder((PCSTR)path); theApp.LogInfo(TEXT("Open game: %s"), (PCTSTR)path); UpdateAllViews(NULL, VIEWUPDATEHINT_RESOURCEMAPCHANGED, pFile); } else { AfxMessageBox(TEXT("SCI game resources must be called resource.map"), MB_OK | MB_ICONEXCLAMATION); } } }
// //创建新的数据保存文件 bool CDlgSavedata::CreatNewFile(CString fileName) { //theApp.str_fileName.Format(_T("%s%s"),_T("SaveData\\"),fileName); //theApp.str_fileName = fileName; CString newfileName; CString directrory; CFile file; CFileException exception;//保存错误信息 directrory = _T("SaveData"); if (! (GetFileAttributes(directrory) == FILE_ATTRIBUTE_DIRECTORY)) //先判断是否存在文件夹,如果不是,则创建文件夹 { if(! CreateDirectory(directrory,NULL)) { MessageBox(_T("创建SaveData文件夹失败!"),NULL,MB_OK|MB_ICONWARNING); return false; } } newfileName.Format(_T("%s\\%s"),directrory,fileName); if (! file.Open(newfileName,CFile::modeCreate | CFile::modeReadWrite, &exception)) //创建文件 { MessageBox(_T("创建保存文件失败!"),NULL,MB_OK|MB_ICONWARNING); return false; } theApp.str_fileName = file.GetFilePath(); return true; }
void CloseLogFile(CFile& file) { if(file.m_hFile != CFile::hFileNull) { CString szFileName = file.GetFilePath(); ULONGLONG uSize = file.GetLength(); file.Close(); if(uSize == 0) CFile::Remove(szFileName); } }
void CBuildMap::OnTimer(UINT nIDEvent) { if(m_PongsTimerID == nIDEvent) { //m_stcNodes.SetWindowText( CommaIze( DWrdtoStr( m_pComm->MapTable.size()))); if(m_Building) { bool Finished = false; CFile NetMap; if( NetMap.Open((m_pDoc->m_RunPath + "Graphing\\graph.gif"), CFile::modeRead, NULL)) { Finished = true; CString Path = NetMap.GetFilePath(); NetMap.Close(); m_pFrame->OpenBrowser(Path); } else { CString Dots; m_btnBuild.GetWindowText(Dots); if(Dots.Find("...") != -1) m_btnBuild.SetWindowText("Building"); else m_btnBuild.SetWindowText(Dots + "."); m_TimeBuilding++; if(m_TimeBuilding == 60) AfxMessageBox("This map has been building for a minute,\r\n your map is probably too big to be created.\r\n\r\nEither continue waiting or use CTRL-ALT-DEL\r\nand Select End Task, Neato.\r\n\r\nLess intensive settings enable the map to be built faster."); // Expand this so gnucleus ends Neato for the user // FindWindow("tty", "Neato"); to get the window } if(Finished) { m_Building = false; m_btnRefresh.EnableWindow(true); m_btnBuild.EnableWindow(true); m_btnBuild.SetWindowText("Build Map"); } } } CDialog::OnTimer(nIDEvent); }
void CSgviewerDoc::Serialize(CArchive& ar) { CSgviewerApp::getApp().setPause( true ); if (ar.IsStoring()) { // TODO: add storing code here } else { try { CFile* file = ar.GetFile(); if ( file ) { Texture::flushTextures(); CString pathstr = file->GetFilePath(); String path = (const char*)pathstr; String dir = File(path).getParent(); P(DirectoryInputStreamArchive) arch = new DirectoryInputStreamArchive; arch->addPath( dir ); P(ModelFileCache) modelcache = new ModelFileCache( arch ); P(SceneFile) sf = new SceneFile( path, modelcache, arch ); modelcache->clear(); scene = sf->scene(); name = path; cube1 = cube2 = 0; prepareDoc(); } } catch ( Throwable& e ) { char buf[1000]; e.getMessage().format().getBytes( buf, sizeof(buf), "ASCII-7" ); if ( CSgviewerApp::getApp().m_pMainWnd ) CSgviewerApp::getApp().m_pMainWnd->MessageBox( buf, "Error - sgviewer", MB_OK|MB_ICONERROR|MB_SYSTEMMODAL ); else MessageBox( 0, buf, "Error - sgviewer", MB_OK|MB_ICONERROR|MB_SYSTEMMODAL ); } } CSgviewerApp::getApp().setPause( false ); }
void CPLYEditorDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here CFile* cfile = ar.GetFile(); CString filename = cfile->GetFilePath(); // return full path and filename //::MessageBox(0, filename, L"Hello", MB_OK); char fn[200]; strcpy(fn, CStringA(filename).GetString()); Mesh* m = readFile(fn); theApp.AddToRecentFileList(filename.GetString()); this->LMesh.push_back(m); this->UpdateAllViews(NULL); } }
void CResourceMapDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // There is nothing to save. int x = 0; } else { CFile *pFile = ar.GetFile(); // Set the current directory, so we know where to look for the resource files. // If not, clicking on an item in the recent documents list won't work CString path = pFile->GetFilePath(); path.MakeLower(); int iFileOffset = path.Find(TEXT("\\resource.map")); if (iFileOffset > 0) { path.SetAt(iFileOffset, 0); // Null terminate it // Set this folder as our new game folder CResourceMap &map = theApp.GetResourceMap(); map.SetGameFolder(path); // Close it. We only wanted the path. pFile->Close(); // Clear the current view. _DeleteAllResourceData(); _DeleteAllPics(); CResourceEnumerator *pEnum; if (SUCCEEDED(map.CreateEnumerator(RTF_PIC, &pEnum))) { CResourceData *pData; while (S_OK == pEnum->Next(&pData)) { // TODO: try catch, and free pData? // Add these resource datas. _resources.Add(pData); // And create a pic from them. CPic *ppic = new CPic(); if (ppic) { if (SUCCEEDED(ppic->InitFromResource(pData))) { _pics.Add(ppic); } else { delete ppic; } } } #ifdef DEBUG INT_PTR iSizeMemory = 0; for (INT_PTR i = 0; i < _pics.GetSize(); i++) { CPic *ppic = _pics.GetAt(i); iSizeMemory += ppic->GetMemorySize(); } TCHAR sz[MAX_PATH]; StringCchPrintf(sz, ARRAYSIZE(sz), TEXT("Memory size of pics: %d"), iSizeMemory); OutputDebugString(sz); #endif SetModifiedFlag(TRUE); UpdateAllViews(NULL, VIEWUPDATEHINT_RESOURCEMAPCHANGED); delete pEnum; } } else { AfxMessageBox(TEXT("SCI game resources must be called resource.map"), MB_OK | MB_ICONEXCLAMATION); } } }
void CTorrent::OnFileHashed() { CFile* pFile = GetFile(); ASSERT(m_TorrentInfo); if(m_TorrentInfo->IsEmpty()) // are we making a torrent { QStringList Shared = theCore->Cfg()->GetStringList("Content/Shared"); Shared.append(theCore->GetIncomingDir()); Shared.append(theCore->GetTempDir()); QList<CTorrentInfo::SFileInfo> Files; if(CJoinedPartMap* pParts = qobject_cast<CJoinedPartMap*>(pFile->GetPartMap())) { QMap<uint64, SPartMapLink*> Links = pParts->GetJoints(); for(QMap<uint64, SPartMapLink*>::iterator I = Links.end(); I != Links.begin();) { SPartMapLink* pLink = *(--I); CFile* pSubFile = pFile->GetList()->GetFileByID(pLink->ID); if(!pSubFile) { LogLine(LOG_DEBUG | LOG_ERROR, tr("A sub file of %1 has been being removed befoure the torrent was created").arg(pFile->GetFileName())); pFile->TorrentHashed(this, false); return; } CTorrentInfo::SFileInfo File; QString Root; QStringList Path = GetRelativeSharedPath(pSubFile->GetFilePath(), Shared, Root).split("/", QString::SkipEmptyParts); if(!Path.isEmpty()) { if(Path.count() > 1) Path.removeFirst(); File.FileName = Path.takeLast(); File.FilePath = Path; } else File.FileName = "unknown"; File.Length = pSubFile->GetFileSize(); Files.append(File); } } if(CFileHashTree* pHashTree = qobject_cast<CFileHashTree*>(m_pHash.data())) m_TorrentInfo->MakeMetadata(Files, pHashTree->GetPartSize(), QList<QByteArray>(), pHashTree->GetRootHash()); else if(CFileHashSet* pHashSet = qobject_cast<CFileHashSet*>(m_pHash.data())) m_TorrentInfo->MakeMetadata(Files, pHashSet->GetPartSize(), pHashSet->GetHashSet()); else { ASSERT(0); } if(!pFile->IsPending()) SaveTorrentToFile(); m_pHash->SetHash(m_TorrentInfo->GetInfoHash()); theCore->m_TorrentManager->RegisterInfoHash(m_TorrentInfo->GetInfoHash()); pFile->TorrentHashed(this, true); } else // we are importing a torrent { bool bMatch = false; if(CFileHashTree* pHashTree = qobject_cast<CFileHashTree*>(m_pHash.data())) bMatch = m_TorrentInfo->GetRootHash() == pHashTree->GetRootHash(); else if(CFileHashSet* pHashSet = qobject_cast<CFileHashSet*>(m_pHash.data())) bMatch = m_TorrentInfo->GetPieceHashes() == pHashSet->GetHashSet(); else { ASSERT(0); } if(bMatch) { if(!pFile->IsPending()) SaveTorrentToFile(); m_pHash->SetHash(m_TorrentInfo->GetInfoHash()); theCore->m_TorrentManager->RegisterInfoHash(m_TorrentInfo->GetInfoHash()); } pFile->TorrentHashed(this, bMatch); } }
void CGenericDoc::Serialize(CArchive& ar) { TRACE("CGenericDoc::Serialize called\n"); BOOL bCanSerialize = TRUE; if(ar.IsLoading()) { #ifdef XP_WIN32 // Determine name of actual document. CFile *pFile = ar.GetFile(); CString csFile; if(pFile) { csFile = pFile->GetFilePath(); } // Determine if this is the same file that was passed into the // OnOpenDocument function. // If so, then we can not read our OLE format. bCanSerialize = (csFile.CompareNoCase(m_csOpenDocumentFile) != 0); // However, if they're both empty, then we need to allow this. if(csFile.IsEmpty() && m_csOpenDocumentFile.IsEmpty()) { bCanSerialize = TRUE; } TRACE("%d = !(%s==%s)\n", bCanSerialize, (const char *)csFile, (const char *)m_csOpenDocumentFile); #else // 16 bit can not turn a file handle into a file name. // If our document name is set, then say we can't serialize. bCanSerialize = !(m_bOpenDocumentFileSet && !m_csOpenDocumentFile.IsEmpty()); TRACE("%d = !(%d && !%d)\n", m_bOpenDocumentFileSet, !m_csOpenDocumentFile.IsEmpty()); #endif } // We can only serialize if we're not looking at a local file which we've opened up. if(bCanSerialize) { // Fleshed out for OLE server work. // The below is the common implementation that should work across the // board for all versions of the navigator. // All it does is either read in or write out a URL. if(GetContext() && GetContext()->IsDestroyed() == FALSE) { if (ar.IsStoring()) { TRACE("Storing\n"); // Just shove our current URL into the file. // Get the current history entry. History_entry *pHist = SHIST_GetCurrent(&(GetContext()->GetContext()->hist)); if(pHist != NULL && pHist->address != NULL) { CString csAddress = pHist->address; ar << csAddress; TRACE("URL is %s\n", (const char *)csAddress); } else { TRACE("no history!\n"); CString csEmpty; ar << csEmpty; } } else { TRACE("Reading\n"); // Pretty much just read this in as internet shortcut // format and load it. CString csLoadMe; ar >> csLoadMe; // Do it. TRACE("URL is %s\n", (const char *)csLoadMe); GetContext()->NormalGetUrl(csLoadMe); } } else { TRACE("no context!\n"); if (ar.IsStoring()) { TRACE("Storing\n"); // Hope that ephemeral data were cached, otherwise, no real // harm done. ar << m_csEphemeralHistoryAddress; } else { TRACE("Reading\n"); CString csDontcare; ar >> csDontcare; } } // Next in line should be a string identifying the client which wrote // out the information. // ALL NUMBERS TO BE CONVERTED TO NETWORK BYTE ORDER, SO WORKS ACROSS PLATFORMS. CString csNetscapeVersion; if(ar.IsStoring()) { // Write out our document version number. // This is initially 2.0 ar << theApp.ResolveAppVersion(); TRACE("App version is %s\n", (const char *)theApp.ResolveAppVersion()); // Write out any other information for a particular version here, // prepended by the amount of total bytes to be written. // Hold all integer values (all XP values) to a size that will // translate between win16 and win32. TRACE("Writing version specific information.\n"); // Figure up the size of extra info we'll be writing out. u_long arExtraBytes = 0; // 3.0 beta 6 has some extra information arExtraBytes += sizeof(u_long); // extent.cx arExtraBytes += sizeof(u_long); // extent.cy arExtraBytes += sizeof(u_long); // extent.cx arExtraBytes += sizeof(u_long); // extent.cy // For version 2.0, there was no extra information. ar << htonl(arExtraBytes); // Now, begin writing out extra information. // 3.0 beta 6 TRACE("3.0 beta 6 and later information being written\n"); ar << htonl((u_long)m_csViewExtent.cx); ar << htonl((u_long)m_csViewExtent.cy); TRACE("Write cx=%lu cy=%lu\n", (uint32)m_csViewExtent.cx, (uint32)m_csViewExtent.cy); ar << htonl((u_long)m_csDocumentExtent.cx); ar << htonl((u_long)m_csDocumentExtent.cy); TRACE("Write cx=%lu cy=%lu\n", (uint32)m_csDocumentExtent.cx, (uint32)m_csDocumentExtent.cy); } else { // Read in our document version number. ar >> csNetscapeVersion; TRACE("App version is %s\n", (const char *)csNetscapeVersion); // Next, read in the amount of bytes that are stored. u_long lBytes; ar >> lBytes; lBytes = ntohl(lBytes); if(lBytes != 0) { // Now, depending on which version we're reading from, // figure out the information in the file if we understand // that particular version's file format. // 2.0 won't understand anything, so just read in the number of // extra bytes and continue. // Let the caller of serialize handle thrown exceptions. TRACE("Reading version specific information of %lu bytes.\n", lBytes); char *pBuf = new char[lBytes]; if(pBuf == NULL) { AfxThrowMemoryException(); } ar.Read((void *)pBuf, CASTUINT(lBytes)); // Use and increment this pointer appropriately to read in // extra information. char *va_start = pBuf; // If and only if there are extra bytes, decide what was written out. // In 3.0 beta 6, we wrote out two uint32's first. u_long arVersion30b6 = 0; arVersion30b6 += sizeof(u_long); arVersion30b6 += sizeof(u_long); arVersion30b6 += sizeof(u_long); arVersion30b6 += sizeof(u_long); // Read in this information, otherwise, use a default. if(lBytes >= arVersion30b6) { TRACE("3.0 beta 6 information being retrieved\n"); m_csViewExtent.cx = CASTINT(ntohl(*((u_long *)va_start))); va_start += sizeof(u_long); m_csViewExtent.cy = CASTINT(ntohl(*((u_long *)va_start))); va_start += sizeof(u_long); TRACE("Read cx=%lu cy=%lu\n", (uint32)m_csViewExtent.cx, (uint32)m_csViewExtent.cy); m_csDocumentExtent.cx = CASTINT(ntohl(*((u_long *)va_start))); va_start += sizeof(u_long); m_csDocumentExtent.cy = CASTINT(ntohl(*((u_long *)va_start))); va_start += sizeof(u_long); TRACE("Read cx=%lu cy=%lu\n", (uint32)m_csDocumentExtent.cx, (uint32)m_csDocumentExtent.cy); } else { TRACE("Using default 3.0 beta 6 information\n"); m_csViewExtent = CSize(HIX, HIY); m_csDocumentExtent = CSize(HIX, HIY); } delete[] pBuf; } } // Calling the base class CGenericDoc enables serialization // of the conainer document's COleclientItem objects. TRACE("Calling base serialize\n"); COleServerDoc::Serialize(ar); }
bool CZipArchive::CloseFile(CFile &file) { CString temp = file.GetFilePath(); file.Close(); return CloseFile(temp); }
void CVertexCollection::Serialize(CArchive& Archive, CTriangulation *Triangulation) { double x = 0; double y = 0; double z = 0; CVertex *Vertex = NULL; CString sLine; if (Archive.IsStoring()) { for (long VertexIndex = 4; VertexIndex < m_Collection.GetCount(); VertexIndex++) { Vertex = (CVertex *)m_Collection[VertexIndex]; sLine.Format(_T(" %.3lf %.3lf %.3lf"),Vertex->m_Coordinate[0],Vertex->m_Coordinate[1], Vertex->m_Coordinate[2]); Archive.WriteString(sLine); Archive.WriteString(_T("\n")); m_VertexNumber++; } } else { //Let's check file extension. CFile *File = Archive.GetFile(); CString FilePath = File->GetFilePath(); char Ext[256]; _splitpath(FilePath, NULL, NULL, NULL, Ext); //First four verteces are verteces of bounding box/ for (int VertexIndex = 0; VertexIndex < 4; VertexIndex++) { Vertex = new CVertex(0, 0, 0, CVertex::BoundingBox); Vertex->m_Index = m_Collection.Add(Vertex); } do { if (!sLine.IsEmpty()) { CString XString; CString YString; CString ZString; int Start = 0; XString = sLine.Tokenize(_T(" "), Start); YString = sLine.Tokenize(_T(" "), Start); ZString = sLine.Tokenize(_T(" "), Start); sscanf_s(XString,_T("%lf.2"), &x); sscanf_s(YString,_T("%lf.2"), &y); sscanf_s(ZString,_T("%lf.2"), &z); Vertex = new CVertex(x, y, z, CVertex::Standalone); Vertex->m_Index = m_Collection.Add(Vertex); if (m_Collection.GetCount() == 5) { m_Min.m_Coordinate[0] = x; m_Min.m_Coordinate[1] = y; m_Min.m_Coordinate[2] = z; m_Max.m_Coordinate[0] = x; m_Max.m_Coordinate[1] = y; m_Max.m_Coordinate[2] = z; } else { //todo = min if (m_Min.m_Coordinate[0] > x) m_Min.m_Coordinate[0] = x; if (m_Min.m_Coordinate[1] > y) m_Min.m_Coordinate[1] = y; if (m_Min.m_Coordinate[2] > z) m_Min.m_Coordinate[2] = z; if (m_Max.m_Coordinate[0] < x) m_Max.m_Coordinate[0] = x; if (m_Max.m_Coordinate[1] < y) m_Max.m_Coordinate[1] = y; if (m_Max.m_Coordinate[2] < z) m_Max.m_Coordinate[2] = z; } } if (m_Collection.GetSize() > 100) break; } while(Archive.ReadString(sLine)); ////////////////////////////////////////// m_DeltaX = 0.25 * fabs((m_Max.m_Coordinate[0] - m_Min.m_Coordinate[0])); m_DeltaY = 0.25 * fabs((m_Max.m_Coordinate[1] - m_Min.m_Coordinate[1])); m_Min.m_Coordinate[2] = (double)((long)m_Min.m_Coordinate[2]); ////////////////////////////////////////////// Vertex = (CVertex *)m_Collection[0]; Vertex->m_Coordinate[0] = m_Min.m_Coordinate[0] - 2 * m_DeltaX; Vertex->m_Coordinate[1] = m_Min.m_Coordinate[1] - 2 * m_DeltaY; Vertex->m_Coordinate[2] = m_Min.m_Coordinate[2]; Vertex = (CVertex *)m_Collection[1]; Vertex->m_Coordinate[0] = m_Max.m_Coordinate[0] + 2 * m_DeltaX; Vertex->m_Coordinate[1] = m_Min.m_Coordinate[1] - 2 * m_DeltaY; Vertex->m_Coordinate[2] = m_Min.m_Coordinate[2]; Vertex = (CVertex *)m_Collection[2]; Vertex->m_Coordinate[0] = m_Max.m_Coordinate[0] + 2 * m_DeltaX; Vertex->m_Coordinate[1] = m_Max.m_Coordinate[1] + 2 * m_DeltaY; Vertex->m_Coordinate[2] = m_Min.m_Coordinate[2]; Vertex = (CVertex *)m_Collection[3]; Vertex->m_Coordinate[0] = m_Min.m_Coordinate[0] - 2 * m_DeltaX; Vertex->m_Coordinate[1] = m_Max.m_Coordinate[1] + 2 * m_DeltaY; Vertex->m_Coordinate[2] = m_Min.m_Coordinate[2]; } }