| 86 | } |
| 87 | |
| 88 | void TuningComponent::exportSCLFileWithFileBrowser() { |
| 89 | DBG("exportSCLFile()"); |
| 90 | |
| 91 | DBG(m_processor.m_tuning.scale.rawText); |
| 92 | |
| 93 | auto suggested_dir = ConfigFileManager::getInstance().getOptionTuningDir(); |
| 94 | |
| 95 | File file_suggestion(suggested_dir + File::getSeparatorString() + "tuning.scl"); |
| 96 | |
| 97 | // set up filechooser |
| 98 | m_filechooser.reset(new FileChooser("Choose a file to save...", file_suggestion, "*.scl", true)); |
| 99 | |
| 100 | //launch filechooser |
| 101 | m_filechooser->launchAsync( |
| 102 | FileBrowserComponent::saveMode | FileBrowserComponent::canSelectFiles, |
| 103 | [file_suggestion, this](const FileChooser &chooser) { |
| 104 | auto result = chooser.getURLResult(); |
| 105 | String file_name = result.isEmpty() ? String() |
| 106 | : (result.isLocalFile() ? result.getLocalFile().getFullPathName() |
| 107 | : result.toString(true)); |
| 108 | |
| 109 | if (file_name != "") { |
| 110 | //append .odin if not already there |
| 111 | file_name = file_name.endsWith(".scl") ? file_name : file_name + ".scl"; |
| 112 | |
| 113 | File file_to_write(file_name); |
| 114 | |
| 115 | //check whether file already exists |
| 116 | if (file_to_write.existsAsFile()) { |
| 117 | if (!(AlertWindow::showOkCancelBox(AlertWindow::WarningIcon, |
| 118 | "File already exists!", |
| 119 | "Are you sure you want to overwrite it?", |
| 120 | {}, |
| 121 | {}, |
| 122 | {}))) { |
| 123 | //user selected cancel |
| 124 | return; |
| 125 | } |
| 126 | } |
| 127 | FileOutputStream file_stream(file_to_write); |
| 128 | |
| 129 | ConfigFileManager::getInstance().saveDataToFile(); |
| 130 | ConfigFileManager::getInstance().setOptionTuningDir( |
| 131 | file_to_write.getParentDirectory().getFullPathName()); |
| 132 | |
| 133 | if (file_stream.openedOk()) { |
| 134 | DBG("Writing tuning file to " << file_to_write.getFullPathName()); |
| 135 | file_stream.setPosition(0); |
| 136 | file_stream << String(m_processor.m_tuning.scale.rawText); |
| 137 | file_stream.flush(); |
| 138 | //savePatchInOpenedFileStream(file_stream); |
| 139 | } else { |
| 140 | AlertWindow::showMessageBox( |
| 141 | AlertWindow::AlertIconType::WarningIcon, |
| 142 | "Unable to save file!", |
| 143 | "Please make sure you have proper write-permissions for the selected directory!"); |
| 144 | } |
| 145 | } |
nothing calls this directly
no test coverage detected