def cleanUpAfterFileSave(fileInfo): useBackup = false renamingFailed = false deletingFailed = false prompt = "" ucursor.cursor_stopWait() uwait.stopWaitMessage() useBackup = true if not fileInfo.writingWasSuccessful: # if couldn't write, then remove temp file and exit without warning DeleteFile(fileInfo.tempFile) return if fileInfo.backupFile != "": if FileExists(fileInfo.backupFile): # remove backup file if exists from prior backup # try to delete backup file deletingFailed = not DeleteFile(fileInfo.backupFile) if deletingFailed: # couldn't delete backup file prompt = "Could not write backup file " + fileInfo.backupFile + ". Continue?" if MessageDialog(prompt, mtConfirmation, [mbYes, mbNo], 0) != mrYes: # user doesn't want to proceed - so cleanup temp file DeleteFile(fileInfo.tempFile) return else: useBackup = false else: useBackup = false if FileExists(fileInfo.newFile): if useBackup: # if original file exists make backup if requested... # rename old copy of new file to make backup renamingFailed = not RenameFile(fileInfo.newFile, fileInfo.backupFile) if renamingFailed: prompt = "Could not rename old file to backup file " + fileInfo.backupFile + ". Continue?" if MessageDialog(prompt, mtConfirmation, [mbYes, mbNo], 0) != mrYes: # user doesn't want to proceed - so cleanup temp file DeleteFile(fileInfo.tempFile) return else: useBackup = false if not useBackup: # could not create backup file - so just delete old file instead of renaming deletingFailed = not DeleteFile(fileInfo.newFile) if deletingFailed: ShowMessage("Could not write file " + fileInfo.newFile) return # rename temp file to newFile name renamingFailed = not RenameFile(fileInfo.tempFile, fileInfo.newFile) if renamingFailed: # clean up by removing temp file ShowMessage("Could not write file " + fileInfo.newFile + " from " + fileInfo.tempFile) DeleteFile(fileInfo.tempFile) return if (not udomain.domain.registered) and (fileInfo.writingWasSuccessful) and (fileIsExportFile(fileInfo.fileType)): umain.MainForm.incrementUnregisteredExportCount()
def loadPlantFileAtStartup(): ucursor.cursor_startWait() try: if udomain.domain.plantFileLoaded: # if file loaded at startup, update for it, else act as if they picked new uwait.startWaitMessage("Drawing...") try: umain.MainForm.updateForPlantFile() finally: uwait.stopWaitMessage() else: umain.MainForm.MenuFileNewClick(umain.MainForm) if usplash.splashForm != None: usplash.splashForm.Hide() umain.MainForm.updateForChangeToDomainOptions() umain.MainForm.updateFileMenuForOtherRecentFiles() umain.MainForm.selectedPlantPartID = -1 umain.MainForm.inFormCreation = false finally: ucursor.cursor_stopWait()