MCPcopy Create free account
hub / github.com/CE-Programming/CEmu / setPortable

Method setPortable

gui/qt/settings.cpp:127–180  ·  view source on GitHub ↗

In all cases, all paths in memory should be absolute paths. But in the UI or config file, they can be relative (to appDir()) if portable mode is enabled, or absolute otherwise.

Source from the content-addressed store, hash-verified

125// In all cases, all paths in memory should be absolute paths.
126// But in the UI or config file, they can be relative (to appDir()) if portable mode is enabled, or absolute otherwise.
127void MainWindow::setPortable(bool state) {
128 ui->checkPortable->blockSignals(true);
129 ui->checkPortable->setChecked(state);
130 ui->checkPortable->blockSignals(false);
131 m_portable = state;
132
133 delete m_config;
134 m_config = Q_NULLPTR;
135
136 const QDir dir = appDir();
137
138 // Get all new paths, in absolute
139 const QString newConfigPath = QFileInfo((state ? dir.path() : configPath) + SETTING_DEFAULT_CONFIG_FILE).absoluteFilePath();
140 const QString newConfigDirPath = QDir::cleanPath(QFileInfo(newConfigPath).absolutePath());
141 QString newDebugPath = newConfigDirPath + SETTING_DEFAULT_DEBUG_FILE;
142 QString newImagePath = newConfigDirPath + SETTING_DEFAULT_IMAGE_FILE;
143 QString newRomPath = m_pathRom; // No change here
144
145 // Update the FS (still using absolute paths)
146 QFile(m_pathConfig).copy(newConfigPath);
147 QFile(m_pathImage).copy(newImagePath);
148
149 // Remove old settings if previously portable
150 if (!state) {
151 QFile(m_pathConfig).remove();
152 QFile(m_pathImage).remove();
153 }
154
155 // Update paths in memory (still using absolute paths)
156 m_pathConfig = newConfigPath;
157 m_pathImage = newImagePath;
158
159 // Now changing the UI and qsettings content, with, if portable, paths relative to appDir()
160 if (state) {
161 newDebugPath = dir.relativeFilePath(newDebugPath);
162 newImagePath = dir.relativeFilePath(newImagePath);
163 newRomPath = dir.relativeFilePath(newRomPath);
164 }
165
166 // Update new QSettings (memory + FS)
167 m_config = new QSettings(newConfigPath, QSettings::IniFormat); // Path is absolute
168 m_config->setValue(SETTING_DEBUGGER_IMAGE_PATH, newDebugPath);
169 m_config->setValue(SETTING_IMAGE_PATH, newImagePath);
170 m_config->setValue(SETTING_ROM_PATH, newRomPath);
171 m_config->sync();
172
173 ui->pathDebug->setText(newDebugPath);
174 ui->pathImage->setText(newImagePath);
175 ui->pathRom->setText(newRomPath);
176 ui->pathConfig->setText(newConfigPath);
177
178 ui->buttonChangeSavedDebugPath->setEnabled(!state);
179 ui->buttonChangeSavedImagePath->setEnabled(!state);
180}
181
182void MainWindow::setFrameskip(int value) {
183 m_config->setValue(SETTING_CAPTURE_FRAMESKIP, value);

Callers

nothing calls this directly

Calls 1

appDirFunction · 0.85

Tested by

no test coverage detected