bool CDataServer::CopyFile(const nString& SrcPath, const nString& DestPath) { //???mangle here for perf reasons? if (IsFileReadOnly(DestPath)) SetFileReadOnly(DestPath, false); CFileStream Src, Dest; if (!Src.Open(SrcPath, SAM_READ, SAP_SEQUENTIAL)) FAIL; if (!Dest.Open(DestPath, SAM_WRITE, SAP_SEQUENTIAL)) { Src.Close(); FAIL; } int Size = Src.GetSize(); char* pBuffer = (char*)n_malloc(Size); int RealSize = Src.Read(pBuffer, Size); n_assert(RealSize == Size); Src.Close(); RealSize = Dest.Write(pBuffer, Size); n_assert(RealSize == Size); Dest.Close(); n_free(pBuffer); OK; }
LEditor *MainBook::OpenFile(const wxString &file_name, const wxString &projectName, int lineno, long position, OF_extra extra/*=OF_AddJump*/, bool preserveSelection /*=true*/) { wxFileName fileName(file_name); fileName.MakeAbsolute(); if(IsFileExists(fileName) == false) { wxLogMessage(wxT("Failed to open: %s: No such file or directory"), fileName.GetFullPath().c_str()); return NULL; } wxString projName = projectName; if (projName.IsEmpty()) { // try to match a project name to the file. otherwise, CC may not work projName = ManagerST::Get()->GetProjectNameByFile(fileName.GetFullPath()); } LEditor* editor = GetActiveEditor(true); BrowseRecord jumpfrom = editor ? editor->CreateBrowseRecord() : BrowseRecord(); editor = FindEditor(fileName.GetFullPath()); if (editor) { editor->SetProject(projName); } else if (fileName.IsOk() == false) { wxLogMessage(wxT("Invalid file name: ") + fileName.GetFullPath()); return NULL; } else if (!fileName.FileExists()) { wxLogMessage(wxT("File: ") + fileName.GetFullPath() + wxT(" does not exist!")); return NULL; } else { // A Nice trick: hide the notebook, open the editor // and then show it bool hidden(false); if(m_book->GetPageCount() == 0) hidden = GetSizer()->Hide(m_book); editor = new LEditor(m_book); editor->Create(projName, fileName); // If we're here from 'Swap Header/Implementation file', insert the new page next door #if !CL_USE_NATIVEBOOK size_t sel = m_book->GetVisibleEditorIndex(); #else size_t sel = (size_t)m_book->GetSelection(); #endif if ((extra & OF_PlaceNextToCurrent) && (sel != Notebook::npos)) { AddPage(editor, fileName.GetFullName(), wxNullBitmap, false, sel+1); } else { AddPage(editor, fileName.GetFullName()); } editor->SetSyntaxHighlight(); // mark the editor as read only if needed MarkEditorReadOnly(editor, IsFileReadOnly(editor->GetFileName())); // SHow the notebook if(hidden) GetSizer()->Show(m_book); if (position == wxNOT_FOUND && lineno == wxNOT_FOUND && editor->GetContext()->GetName() == wxT("C++")) { // try to find something interesting in the file to put the caret at // for now, just skip past initial blank lines and comments for (lineno = 0; lineno < editor->GetLineCount(); lineno++) { switch (editor->GetStyleAt(editor->PositionFromLine(lineno))) { case wxSTC_C_DEFAULT: case wxSTC_C_COMMENT: case wxSTC_C_COMMENTDOC: case wxSTC_C_COMMENTLINE: case wxSTC_C_COMMENTLINEDOC: continue; } // if we got here, it's a line to stop on break; } if (lineno == editor->GetLineCount()) { lineno = 1; // makes sure a navigation record gets saved } } } if (position != wxNOT_FOUND) { editor->SetEnsureCaretIsVisible(position, preserveSelection); } else if (lineno != wxNOT_FOUND) { editor->SetEnsureCaretIsVisible(editor->PositionFromLine(lineno), preserveSelection); } if (m_reloadingDoRaise) { if (GetActiveEditor() == editor) { editor->SetActive(); } else { SelectPage(editor); } } // Add this file to the history. Don't check for uniqueness: // if it's already on the list, wxFileHistory will move it to the top // Also, sync between the history object and the configuration file m_recentFiles.AddFileToHistory ( fileName.GetFullPath() ); wxArrayString files; m_recentFiles.GetFiles ( files ); EditorConfigST::Get()->SetRecentItems( files, wxT("RecentFiles") ); if (extra & OF_AddJump) { BrowseRecord jumpto = editor->CreateBrowseRecord(); NavMgr::Get()->AddJump(jumpfrom, jumpto); } #if !CL_USE_NATIVEBOOK if(m_book->GetPageCount() == 1) { m_book->GetSizer()->Layout(); } #endif return editor; }