MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / apply

Method apply

src/Gui/PreferencePackManager.cpp:91–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91bool 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
143App::Metadata Gui::PreferencePack::metadata() const

Callers

nothing calls this directly

Calls 12

getSavedPrefPacksPathFunction · 0.85
runFileMethod · 0.80
SaveDocumentMethod · 0.80
LoadDocumentMethod · 0.80
loadStateMethod · 0.80
instanceFunction · 0.70
removeFunction · 0.50
c_strMethod · 0.45
messageMethod · 0.45
findMethod · 0.45
endMethod · 0.45
restoreStateMethod · 0.45

Tested by

no test coverage detected