bool FileStdStream::PutC(int nChar) { #ifdef WIN32 // Write character if (IsWritable()) return ((m_nStringFormat == String::ASCII) ? putc(nChar, m_pFile) : putwc(static_cast<wchar_t>(nChar), m_pFile)) != 0; // Error! return false; #else // Write character return (m_pFile && IsWritable() && putc(nChar, m_pFile) != EOF); #endif }
int FileStdStream::PutS(const String &sString) { // Write string if (m_pFile && IsWritable()) { #ifdef WIN32 // ASCII or Unicode? if (m_nStringFormat == String::ASCII) { const int nSize = fputs(sString.GetASCII(), m_pFile); if (nSize >= 0) return sString.GetLength(); } else { const int nSize = fputws(sString.GetUnicode(), m_pFile); if (nSize >= 0) return sString.GetLength(); } #else const int nSize = fputs((sString.GetFormat() == String::ASCII) ? sString.GetASCII() : sString.GetUTF8(), m_pFile); if (nSize >= 0) return sString.GetLength(); #endif } // Error! return -1; }
void SCH_EDIT_FRAME::SaveProjectSettings( bool aAskForSave ) { PROJECT& prj = Prj(); wxFileName fn = g_RootSheet->GetScreen()->GetFileName(); //ConfigFileName fn.SetExt( ProjectFileExtension ); if( !IsWritable( fn ) ) return; if( aAskForSave ) { wxFileDialog dlg( this, _( "Save Project File" ), fn.GetPath(), fn.GetFullName(), ProjectFileWildcard(), wxFD_SAVE ); if( dlg.ShowModal() == wxID_CANCEL ) return; fn = dlg.GetPath(); } wxString path = fn.GetFullPath(); prj.ConfigSave( Kiface().KifaceSearch(), GROUP_SCH_EDIT, GetProjectFileParameters(), path ); }
void CVPCB_MAINFRAME::SaveProjectFile( wxCommandEvent& aEvent ) { wxFileName fn = m_NetlistFileName; fn.SetExt( ProjectFileExtension ); if( aEvent.GetId() == ID_SAVE_PROJECT_AS || !m_NetlistFileName.IsOk() ) { wxFileDialog dlg( this, _( "Save Project File" ), fn.GetPath(), wxEmptyString, ProjectFileWildcard, wxFD_SAVE ); if( dlg.ShowModal() == wxID_CANCEL ) return; fn = dlg.GetPath(); if( !fn.HasExt() ) fn.SetExt( ProjectFileExtension ); } if( !IsWritable( fn ) ) return; // was: // Pgm().WriteProjectConfig( fn.GetFullPath(), GROUP, GetProjectFileParameters() ); PROJECT& prj = Prj(); SEARCH_STACK& search = prj.SchSearchS(); prj.ConfigSave( search, fn.GetFullPath(), GROUP, GetProjectFileParameters() ); }
void SCH_EDIT_FRAME::OnSaveProject( wxCommandEvent& aEvent ) { SCH_SCREEN* screen; wxFileName fn; wxFileName tmp; SCH_SCREENS ScreenList; fn = g_RootSheet->GetFileName(); // Ensure a path exists. if no path, assume the cwd is used // The IsWritable function expects the path to be set if( !fn.GetPath().IsEmpty() ) tmp.AssignDir( fn.GetPath() ); else tmp.AssignDir( wxGetCwd() ); if( !IsWritable( tmp ) ) return; for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() ) SaveEEFile( screen ); CreateArchiveLibraryCacheFile(); UpdateTitle(); }
BOOL ModuleRoot::GetRootProperty(Var originalInstance, PropertyId propertyId, Var* value, PropertyValueInfo* info, ScriptContext* requestContext) { PropertyIndex index = GetRootPropertyIndex(propertyId); if (index != Constants::NoSlot) { *value = this->GetSlot(index); if (info) // Avoid testing IsWritable if info not being queried { PropertyValueInfo::Set(info, this, index, IsWritable(propertyId) ? PropertyWritable : PropertyNone); if (this->IsFixedProperty(propertyId)) { PropertyValueInfo::DisableStoreFieldCache(info); } } return TRUE; } if (this->hostObject && JavascriptOperators::GetProperty(this->hostObject, propertyId, value, requestContext)) { return TRUE; } // // Try checking the global object // if the module root doesn't have the property and the host object also doesn't have it // GlobalObject* globalObj = this->GetLibrary()->GetGlobalObject(); return globalObj->GlobalObject::GetRootProperty(originalInstance, propertyId, value, NULL, requestContext); }
HXBOOL CHXDirectory::SetTempPath(HXXHANDLE , const char* szRelPath) { // caller must specify a sub-directory if ((szRelPath == NULL) || (szRelPath[0] == '\0')) { return FALSE; } m_strPath.Empty(); // try current working directory if (!SetCurrentDir() || !IsWritable(m_strPath)) { return FALSE; } // now append the sub-directory, separating if necessary if ((m_strPath.IsEmpty() || (m_strPath.Right(1) != OS_SEPARATOR_STRING)) && (szRelPath[0] != OS_SEPARATOR_CHAR)) { m_strPath += OS_SEPARATOR_STRING; } m_strPath += szRelPath; if (m_strPath.Right(1) != OS_SEPARATOR_STRING) { m_strPath += OS_SEPARATOR_STRING; } return TRUE; }
bool Stream_File::Open(Signal &sig, const char *fileName, UInt32 attr) { Close(); _attr |= attr; _fileName = OAL::MakeAbsPathName(OAL::FileSeparator, fileName); DWORD dwDesiredAccess = IsAppend()? GENERIC_WRITE : IsReadable()? GENERIC_READ : IsWritable()? GENERIC_WRITE : GENERIC_READ; DWORD dwShareMode = FILE_SHARE_READ; DWORD dwCreationDisposition = IsAppend()? OPEN_ALWAYS : IsReadable()? OPEN_EXISTING : IsWritable()? CREATE_ALWAYS : OPEN_EXISTING; _hFile = ::CreateFile(OAL::ToNativeString(_fileName.c_str()).c_str(), dwDesiredAccess, dwShareMode, nullptr, dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, nullptr); if (_hFile == INVALID_HANDLE_VALUE) { sig.SetError(ERR_IOError, "can't open file '%s'", fileName); return false; } if (IsAppend()) { ::SetFilePointer(_hFile, 0, nullptr, FILE_END); } _map.hFileMappingObject = nullptr; _map.buff = nullptr; _map.bytes = 0; _map.offset = 0; _needCloseFlag = true; if (dwDesiredAccess == GENERIC_READ) { _map.hFileMappingObject = ::CreateFileMapping(_hFile, nullptr, PAGE_READONLY, 0, 0, nullptr); if (_map.hFileMappingObject == nullptr) { // it seems to open an empty file return true; } _map.buff = reinterpret_cast<UChar *>( ::MapViewOfFile(_map.hFileMappingObject, FILE_MAP_READ, 0, 0, 0)); _map.bytes = ::GetFileSize(_hFile, nullptr); _map.offset = 0; } return true; }
MemoryStreamFixedExt CreateMemoryStream( uiw offset = 0 ) { ASSUME( IsOpened() ); if( IsWritable() ) { return MemoryStreamFixedExt( Memory(), Size(), offset ); } return MemoryStreamFixedExt( CMemory(), Size(), offset ); }
ssize_t EFile::WriteAt(eint64 pos, const void *buffer, size_t size) { if(!IsWritable() || buffer == NULL) return -1; eint64 savePosition = Position(); if(Seek(pos, E_SEEK_SET) < E_INT64_CONSTANT(0)) return -1; ssize_t retVal = Write(buffer, size); Seek(savePosition, E_SEEK_SET); return retVal; }
void CLeftView::UseRightFile() { int nFirstViewLine = 0; int nLastViewLine = GetViewCount()-1; if (!IsWritable()) return; ClearSelection(); return UseViewBlock(m_pwndRight, nFirstViewLine, nLastViewLine); }
ssize_t EFile::Write(const void *buffer, size_t size) { if(!IsWritable() || buffer == NULL) return -1; #ifndef _WIN32 return write(*((int*)fFD), buffer, size); #else DWORD nWrote = (DWORD)size; if(WriteFile((HANDLE)fFD, buffer, nWrote, &nWrote, NULL) == 0) return -1; return((ssize_t)nWrote); #endif }
void CLeftView::UseRightBlock() { int nFirstViewLine = 0; int nLastViewLine = 0; if (!IsWritable()) return; if (!GetViewSelection(nFirstViewLine, nLastViewLine)) return; return UseViewBlock(m_pwndRight, nFirstViewLine, nLastViewLine); }
BOOL ES5Array::SetPropertyWithAttributes(PropertyId propertyId, Var value, PropertyAttributes attributes, PropertyValueInfo* info, PropertyOperationFlags flags, SideEffects possibleSideEffects) { if (propertyId == PropertyIds::length) { Assert(attributes == PropertyWritable); Assert(IsWritable(propertyId) && !IsConfigurable(propertyId) && !IsEnumerable(propertyId)); uint32 newLen = ToLengthValue(value, GetScriptContext()); GetTypeHandler()->SetLength(this, newLen, PropertyOperation_None); return true; } return __super::SetPropertyWithAttributes(propertyId, value, attributes, info, flags, possibleSideEffects); }
bool PCB_EDIT_FRAME::SavePcbCopy( const wxString& aFileName ) { wxFileName pcbFileName = aFileName; // Ensure the file ext is the right ext: pcbFileName.SetExt( KiCadPcbFileExtension ); if( !IsWritable( pcbFileName ) ) { wxString msg = wxString::Format( _( "No access rights to write to file '%s'" ), GetChars( pcbFileName.GetFullPath() ) ); DisplayError( this, msg ); return false; } GetBoard()->m_Status_Pcb &= ~CONNEXION_OK; GetBoard()->SynchronizeNetsAndNetClasses(); // Select default Netclass before writing file. // Useful to save default values in headers SetCurrentNetClass( NETCLASS::Default ); try { PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::KICAD ) ); wxASSERT( pcbFileName.IsAbsolute() ); pi->Save( pcbFileName.GetFullPath(), GetBoard(), NULL ); } catch( const IO_ERROR& ioe ) { wxString msg = wxString::Format( _( "Error saving board file '%s'.\n%s" ), GetChars( pcbFileName.GetFullPath() ), GetChars( ioe.errorText ) ); DisplayError( this, msg ); return false; } DisplayInfoMessage( this, wxString::Format( _( "Board copied to:\n'%s'" ), GetChars( pcbFileName.GetFullPath() ) ) ); return true; }
socketState TCPSocket::State() const { CoreAssert(this != NULL); /* Make sure there have been no spontaneous state changes. */ switch (m_state) { case SOCKET_STATE_CONNECTING: { if (IsReadable() || IsWritable()) m_state = SOCKET_STATE_CONNECTED; } default: break; } return m_state; }
bool SCH_EDIT_FRAME::doAutoSave() { wxFileName tmpFileName = g_RootSheet->GetFileName(); wxFileName fn = tmpFileName; wxFileName tmp; SCH_SCREENS screens; bool autoSaveOk = true; tmp.AssignDir( fn.GetPath() ); if( !IsWritable( tmp ) ) return false; for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() ) { // Only create auto save files for the schematics that have been modified. if( !screen->IsSave() ) continue; tmpFileName = fn = screen->GetFileName(); // Auto save file name is the normal file name prefixed with $. fn.SetName( wxT( "$" ) + fn.GetName() ); screen->SetFileName( fn.GetFullPath() ); if( SaveEEFile( screen, false, NO_BACKUP_FILE ) ) screen->SetModify(); else autoSaveOk = false; screen->SetFileName( tmpFileName.GetFullPath() ); } if( autoSaveOk ) m_autoSaveState = false; return autoSaveOk; }
bool WaypointGlue::SaveWaypointFile(const Waypoints &way_points, int num) { if (!IsWritable(num)) { LogFormat("Waypoint file %d can not be written", num); return false; } TCHAR file[255]; GetPath(num, file); TextWriter writer(file); if (!writer.IsOpen()) { LogFormat("Waypoint file %d can not be written", num); return false; } WaypointWriter wp_writer(way_points, num); wp_writer.Save(writer, DetermineWaypointFileType(file)); LogFormat("Waypoint file %d saved", num); return true; }
bool WaypointGlue::SaveWaypointFile(const Waypoints &way_points, int num) { if (!IsWritable(num)) { LogStartUp(_T("Waypoint file %d can not be written"), num); return false; } TCHAR file[255]; GetPath(num, file); TextWriter writer(file); if (writer.error()) { LogStartUp(_T("Waypoint file %d can not be written"), num); return false; } WaypointWriter wp_writer(way_points, num); wp_writer.Save(writer); LogStartUp(_T("Waypoint file %d saved"), num); return true; }
bool WayPointFile::Save(const Waypoints &way_points) { // No filename -> return if (file[0] == 0) return false; // Not writable -> return if (!IsWritable()) return false; // Compressed file -> return if (compressed) return false; // Try to open waypoint file for writing TextWriter writer(file); if (writer.error()) return false; saveFile(writer, way_points); // and tell everyone we saved successfully return true; }
bool Stream_File::Open(Signal &sig, const char *fileName, UInt32 attr) { Close(); _attr |= attr; _fileName = OAL::MakeAbsPathName(OAL::FileSeparator, fileName); char modeMod[8]; if (IsAppend()) { modeMod[0] = 'a'; } else if (IsReadable()) { modeMod[0] = 'r'; } else if (IsWritable()) { modeMod[0] = 'w'; } else { modeMod[0] = 'r'; } modeMod[1] = '\0'; _fp = ::fopen(OAL::ToNativeString(_fileName.c_str()).c_str(), modeMod); if (_fp == nullptr) { sig.SetError(ERR_IOError, "can't open file '%s'", fileName); return false; } _needCloseFlag = true; return true; }
bool WaypointGlue::IsWritable() { return IsWritable(1) || IsWritable(2) || IsWritable(3); }
bool com_ximeta_driver_NDASPhysicalUnitDevice::writeSectorsOnce(UInt64 location, UInt32 sectors, char *buffer) { ManagingIOCommand managingCommand; com_ximeta_driver_NDASCommand *NDASCommand; com_ximeta_driver_NDASDeviceController *deviceController; bool result; if (false ==IsWritable()) { DbgIOLog(DEBUG_MASK_DISK_ERROR, ("writeSectorsOnce: No Write right!\n")); return false; } managingCommand.device = this; managingCommand.command = kNDASManagingIOWriteSectors; managingCommand.IsSuccess = false; managingCommand.Location = location; managingCommand.sectors = sectors; managingCommand.buffer = buffer; // Create NDAS Command. NDASCommand = OSDynamicCast(com_ximeta_driver_NDASCommand, OSMetaClass::allocClassWithName(NDAS_COMMAND_CLASS)); if(NDASCommand == NULL || !NDASCommand->init()) { DbgIOLog(DEBUG_MASK_NDAS_ERROR, ("writeSectorsOnce: failed to alloc command class\n")); if (NDASCommand) { NDASCommand->release(); } return false; } NDASCommand->setCommand(&managingCommand); // Send Command. deviceController = OSDynamicCast(com_ximeta_driver_NDASDeviceController, getParentEntry(gIOServicePlane)); if (NULL == deviceController) { DbgIOLog(DEBUG_MASK_NDAS_ERROR, ("writeSectorsOnce: Can't Find controller.\n")); return false; } this->retain(); if (false == deviceController->executeAndWaitCommand(NDASCommand)) { DbgIOLog(DEBUG_MASK_NDAS_ERROR, ("writeSectorsOnce: Can't execute command.\n")); return false; } result = NDASCommand->managingIOCommand()->IsSuccess; if (false == result) { DbgIOLog(DEBUG_MASK_NDAS_ERROR, ("writeSectorsOnce: Managing IO failed.\n")); } this->release(); NDASCommand->release(); return result; }
bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupFile ) { // please, keep it simple. prompting goes elsewhere. wxFileName pcbFileName = aFileName; if( pcbFileName.GetExt() == LegacyPcbFileExtension ) pcbFileName.SetExt( KiCadPcbFileExtension ); if( !IsWritable( pcbFileName ) ) { wxString msg = wxString::Format( _( "No access rights to write to file \"%s\"" ), GetChars( pcbFileName.GetFullPath() ) ); DisplayError( this, msg ); return false; } wxString backupFileName; if( aCreateBackupFile ) { backupFileName = createBackupFile( aFileName ); } GetBoard()->SynchronizeNetsAndNetClasses(); // Select default Netclass before writing file. // Useful to save default values in headers SetCurrentNetClass( NETCLASS::Default ); ClearMsgPanel(); wxString upperTxt; wxString lowerTxt; try { PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::KICAD_SEXP ) ); wxASSERT( pcbFileName.IsAbsolute() ); pi->Save( pcbFileName.GetFullPath(), GetBoard(), NULL ); } catch( const IO_ERROR& ioe ) { wxString msg = wxString::Format( _( "Error saving board file \"%s\".\n%s" ), GetChars( pcbFileName.GetFullPath() ), GetChars( ioe.What() ) ); DisplayError( this, msg ); lowerTxt.Printf( _( "Failed to create \"%s\"" ), GetChars( pcbFileName.GetFullPath() ) ); AppendMsgPanel( upperTxt, lowerTxt, CYAN ); return false; } GetBoard()->SetFileName( pcbFileName.GetFullPath() ); UpdateTitle(); // Put the saved file in File History, unless aCreateBackupFile // is false. // aCreateBackupFile == false is mainly used to write autosave files // and not need to have an autosave file in file history if( aCreateBackupFile ) UpdateFileHistory( GetBoard()->GetFileName() ); // Delete auto save file on successful save. wxFileName autoSaveFileName = pcbFileName; autoSaveFileName.SetName( GetAutoSaveFilePrefix() + pcbFileName.GetName() ); if( autoSaveFileName.FileExists() ) wxRemoveFile( autoSaveFileName.GetFullPath() ); if( !!backupFileName ) upperTxt.Printf( _( "Backup file: \"%s\"" ), GetChars( backupFileName ) ); lowerTxt.Printf( _( "Wrote board file: \"%s\"" ), GetChars( pcbFileName.GetFullPath() ) ); AppendMsgPanel( upperTxt, lowerTxt, CYAN ); GetScreen()->ClrModify(); GetScreen()->ClrSave(); return true; }
bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, bool aSaveUnderNewName, bool aCreateBackupFile ) { wxString msg; wxFileName schematicFileName; bool success; if( aScreen == NULL ) aScreen = GetScreen(); // If no name exists in the window yet - save as new. if( aScreen->GetFileName().IsEmpty() ) aSaveUnderNewName = true; // Construct the name of the file to be saved schematicFileName = Prj().AbsolutePath( aScreen->GetFileName() ); if( aSaveUnderNewName ) { wxFileDialog dlg( this, _( "Schematic Files" ), wxPathOnly( Prj().GetProjectFullName() ), schematicFileName.GetFullName(), SchematicFileWildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); if( dlg.ShowModal() == wxID_CANCEL ) return false; schematicFileName = dlg.GetPath(); if( schematicFileName.GetExt() != SchematicFileExtension ) schematicFileName.SetExt( SchematicFileExtension ); } if( !IsWritable( schematicFileName ) ) return false; // Create backup if requested if( aCreateBackupFile && schematicFileName.FileExists() ) { wxFileName backupFileName = schematicFileName; // Rename the old file to a '.bak' one: backupFileName.SetExt( SchematicBackupFileExtension ); if( backupFileName.FileExists() ) wxRemoveFile( backupFileName.GetFullPath() ); if( !wxRenameFile( schematicFileName.GetFullPath(), backupFileName.GetFullPath() ) ) { msg.Printf( _( "Could not save backup of file '%s'" ), GetChars( schematicFileName.GetFullPath() ) ); DisplayError( this, msg ); } } // Save wxLogTrace( traceAutoSave, wxT( "Saving file <" ) + schematicFileName.GetFullPath() + wxT( ">" ) ); FILE* f = wxFopen( schematicFileName.GetFullPath(), wxT( "wt" ) ); if( !f ) { msg.Printf( _( "Failed to create file '%s'" ), GetChars( schematicFileName.GetFullPath() ) ); DisplayError( this, msg ); return false; } success = aScreen->Save( f ); if( success ) { // Delete auto save file. wxFileName autoSaveFileName = schematicFileName; autoSaveFileName.SetName( wxT( "$" ) + schematicFileName.GetName() ); if( autoSaveFileName.FileExists() ) { wxLogTrace( traceAutoSave, wxT( "Removing auto save file <" ) + autoSaveFileName.GetFullPath() + wxT( ">" ) ); wxRemoveFile( autoSaveFileName.GetFullPath() ); } // Update the screen and frame info. if( aSaveUnderNewName ) aScreen->SetFileName( schematicFileName.GetFullPath() ); aScreen->ClrSave(); aScreen->ClrModify(); msg.Printf( _( "File %s saved" ), GetChars( aScreen->GetFileName() ) ); SetStatusText( msg, 0 ); } else { DisplayError( this, _( "File write operation failed." ) ); } fclose( f ); return success; }
bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, bool aSaveUnderNewName, bool aCreateBackupFile ) { wxString msg; wxFileName schematicFileName; FILE* f; bool success; if( aScreen == NULL ) aScreen = GetScreen(); // If no name exists in the window yet - save as new. if( aScreen->GetFileName().IsEmpty() ) aSaveUnderNewName = true; // Construct the name of the file to be saved schematicFileName = aScreen->GetFileName(); if( aSaveUnderNewName ) { wxFileDialog dlg( this, _( "Schematic Files" ), wxGetCwd(), schematicFileName.GetFullName(), SchematicFileWildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); if( dlg.ShowModal() == wxID_CANCEL ) return false; schematicFileName = dlg.GetPath(); if( schematicFileName.GetExt() != SchematicFileExtension ) schematicFileName.SetExt( SchematicFileExtension ); } else { // Sheet file names are relative to the root sheet path which is the current // working directory. The IsWritable function expects the path to be set. if( schematicFileName.GetPath().IsEmpty() ) schematicFileName.Assign( wxFileName::GetCwd(), schematicFileName.GetFullName() ); } if( !IsWritable( schematicFileName ) ) return false; /* Create backup if requested */ if( aCreateBackupFile && schematicFileName.FileExists() ) { wxFileName backupFileName = schematicFileName; /* Rename the old file to a '.bak' one: */ backupFileName.SetExt( SchematicBackupFileExtension ); if( backupFileName.FileExists() ) wxRemoveFile( backupFileName.GetFullPath() ); if( !wxRenameFile( schematicFileName.GetFullPath(), backupFileName.GetFullPath() ) ) { msg.Printf( _( "Could not save backup of file <%s>" ), GetChars( schematicFileName.GetFullPath() ) ); DisplayError( this, msg ); } } /* Save */ wxLogTrace( traceAutoSave, wxT( "Saving file <" ) + schematicFileName.GetFullPath() + wxT( ">" ) ); if( ( f = wxFopen( schematicFileName.GetFullPath(), wxT( "wt" ) ) ) == NULL ) { msg.Printf( _( "Failed to create file <%s>" ), GetChars( schematicFileName.GetFullPath() ) ); DisplayError( this, msg ); return false; } success = aScreen->Save( f ); if( success ) { // Delete auto save file. wxFileName autoSaveFileName = schematicFileName; autoSaveFileName.SetName( wxT( "$" ) + schematicFileName.GetName() ); if( autoSaveFileName.FileExists() ) { wxLogTrace( traceAutoSave, wxT( "Removing auto save file <" ) + autoSaveFileName.GetFullPath() + wxT( ">" ) ); wxRemoveFile( autoSaveFileName.GetFullPath() ); } // Update the screen and frame info. if( aSaveUnderNewName ) aScreen->SetFileName( schematicFileName.GetFullPath() ); aScreen->ClrSave(); aScreen->ClrModify(); msg.Printf( _( "File %s saved" ), GetChars( aScreen->GetFileName() ) ); SetStatusText( msg, 0 ); } else { DisplayError( this, _( "File write operation failed." ) ); } fclose( f ); return success; }
bool LIB_EDIT_FRAME::SaveActiveLibrary( bool newFile ) { wxFileName fn; wxString msg; m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); PART_LIB* lib = GetCurLib(); // Just in case the library hasn't been cached yet. lib->GetCount(); if( !lib ) { DisplayError( this, _( "No library specified." ) ); return false; } wxString oldFileName = lib->GetFullFileName(); if( GetScreen()->IsModify() ) { if( IsOK( this, _( "Include last component changes?" ) ) ) { lib->EnableBuffering(); try { SaveOnePart( lib, false ); } catch( ... ) { lib->EnableBuffering( false ); msg.Printf( _( "Unexpected error occured saving part to '%s' symbol library." ), lib->GetName() ); DisplayError( this, msg ); return false; } lib->EnableBuffering( false ); } } if( newFile ) { PROJECT& prj = Prj(); SEARCH_STACK* search = prj.SchSearchS(); // Get a new name for the library wxString default_path = prj.GetRString( PROJECT::SCH_LIB_PATH ); if( !default_path ) default_path = search->LastVisitedPath(); wxFileDialog dlg( this, _( "Part Library Name:" ), default_path, wxEmptyString, SchematicLibraryFileWildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); if( dlg.ShowModal() == wxID_CANCEL ) return false; fn = dlg.GetPath(); // The GTK file chooser doesn't return the file extension added to // file name so add it here. if( fn.GetExt().IsEmpty() ) fn.SetExt( SchematicLibraryFileExtension ); prj.SetRString( PROJECT::SCH_LIB_PATH, fn.GetPath() ); } else { fn = wxFileName( lib->GetFullFileName() ); msg.Printf( _( "Modify library file '%s' ?" ), GetChars( fn.GetFullPath() ) ); if( !IsOK( this, msg ) ) return false; } // Verify the user has write privileges before attempting to save the library file. if( !IsWritable( fn ) ) return false; ClearMsgPanel(); wxFileName libFileName = fn; wxFileName backupFileName = fn; // Rename the old .lib file to .bak. if( libFileName.FileExists() ) { backupFileName.SetExt( "bak" ); if( backupFileName.FileExists() ) wxRemoveFile( backupFileName.GetFullPath() ); if( !wxRenameFile( libFileName.GetFullPath(), backupFileName.GetFullPath() ) ) { libFileName.MakeAbsolute(); msg = _( "Failed to rename old component library file " ) + backupFileName.GetFullPath(); DisplayError( this, msg ); } } wxFileName docFileName = libFileName; docFileName.SetExt( DOC_EXT ); // Rename .doc file to .bck. if( docFileName.FileExists() ) { backupFileName.SetExt( "bck" ); if( backupFileName.FileExists() ) wxRemoveFile( backupFileName.GetFullPath() ); if( !wxRenameFile( docFileName.GetFullPath(), backupFileName.GetFullPath() ) ) { msg = _( "Failed to save old library document file " ) + backupFileName.GetFullPath(); DisplayError( this, msg ); } } try { lib->SetFileName( fn.GetFullPath() ); lib->Save(); } catch( ... /* IO_ERROR ioe */ ) { lib->SetFileName( oldFileName ); msg.Printf( _( "Failed to create symbol library file '%s'" ), GetChars( docFileName.GetFullPath() ) ); DisplayError( this, msg ); return false; } lib->SetFileName( oldFileName ); msg.Printf( _( "Library file '%s' saved" ), GetChars( fn.GetFullPath() ) ); fn.SetExt( DOC_EXT ); wxString msg1; msg1.Printf( _( "Documentation file '%s' saved" ), GetChars( fn.GetFullPath() ) ); AppendMsgPanel( msg, msg1, BLUE ); UpdateAliasSelectList(); UpdatePartSelectList(); refreshSchematic(); return true; }
bool Stream::CheckWritable(Signal &sig) const { if (IsWritable()) return true; sig.SetError(ERR_IOError, "stream is not writable"); return false; }
uint32 FileStdStream::Write(const void *pBuffer, uint32 nSize, uint32 nCount) { // Write buffer return m_pFile && IsWritable() ? static_cast<uint32>(fwrite(pBuffer, nSize, nCount, m_pFile)) : 0; }
bool CppINode::isWritable() { return IsWritable(_node->GetAccessMode()); }