| 89 | } |
| 90 | |
| 91 | bool PreferencePack::apply() const |
| 92 | { |
| 93 | // Run the pre.FCMacro, if it exists: if it raises an exception, abort the process |
| 94 | auto preMacroPath = _path / "pre.FCMacro"; |
| 95 | if (fs::exists(preMacroPath)) { |
| 96 | try { |
| 97 | Base::Interpreter().runFile(Base::FileInfo::pathToString(preMacroPath).c_str(), false); |
| 98 | } |
| 99 | catch (...) { |
| 100 | Base::Console().message( |
| 101 | "PreferencePack application aborted by the preferencePack's pre.FCMacro" |
| 102 | ); |
| 103 | return false; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | // Back up the old config file |
| 108 | auto savedPreferencePacksDirectory = getSavedPrefPacksPath(); |
| 109 | auto backupFile = savedPreferencePacksDirectory / "user.cfg.backup"; |
| 110 | try { |
| 111 | fs::remove(backupFile); |
| 112 | } |
| 113 | catch (...) { |
| 114 | } |
| 115 | App::GetApplication().GetUserParameter().SaveDocument( |
| 116 | Base::FileInfo::pathToString(backupFile).c_str() |
| 117 | ); |
| 118 | |
| 119 | // Apply the config settings |
| 120 | applyConfigChanges(); |
| 121 | |
| 122 | // Run the Post.FCMacro, if it exists |
| 123 | auto postMacroPath = _path / "post.FCMacro"; |
| 124 | if (fs::exists(postMacroPath)) { |
| 125 | try { |
| 126 | Base::Interpreter().runFile(Base::FileInfo::pathToString(postMacroPath).c_str(), false); |
| 127 | } |
| 128 | catch (...) { |
| 129 | Base::Console().message( |
| 130 | "PreferencePack application reverted by the preferencePack's post.FCMacro" |
| 131 | ); |
| 132 | App::GetApplication().GetUserParameter().LoadDocument( |
| 133 | Base::FileInfo::pathToString(backupFile).c_str() |
| 134 | ); |
| 135 | return false; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | return true; |
| 140 | } |
| 141 | |
| 142 | |
| 143 | App::Metadata Gui::PreferencePack::metadata() const |
nothing calls this directly
no test coverage detected