Skip to content

Commit

Permalink
Let's keep a copy of the .ini's in the parent
Browse files Browse the repository at this point in the history
folder.  This allows us to easily copy them down again when we install a
new version because squirrel puts the new version in a new folder.
Probably we should just teach gpx.exe where to find the gpx.ini in the
unversioned appdata folder, but for now we'll leave it as is so that
people can use their own version of gpx.exe (would that happen?)
  • Loading branch information
markwal committed Aug 21, 2015
1 parent 9348fb6 commit 05d3523
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
29 changes: 19 additions & 10 deletions iniedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern "C" {
}

#include <QString>
#include <QDir>
#include <QTextStream>
QTextStream &qStdout();

Expand Down Expand Up @@ -104,19 +105,27 @@ bool IniEditor::read(ParserCallback pc = NULL, void *user = NULL)
return true;
}

bool IniEditor::write()
bool IniEditor::write(bool fCopyToParent)
{
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return false;
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return false;

QTextStream ts(&file);
for (ConstLineIterator iline = ll.constBegin(); iline != ll.constEnd(); iline++) {
if (!iline->fDeleted)
ts << iline->sLine << "\n";
}

QTextStream ts(&file);
for (ConstLineIterator iline = ll.constBegin(); iline != ll.constEnd(); iline++) {
if (!iline->fDeleted)
ts << iline->sLine << "\n";
}
file.close();

file.close();
return true;
if (fCopyToParent) {
QFileInfo fi(file.fileName());
QDir dir(fi.absoluteDir());
dir.cdUp();
file.copy(dir.absoluteFilePath(fi.fileName()));
}

return true;
}

void Section::dump() const
Expand Down
2 changes: 1 addition & 1 deletion iniedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class IniEditor
void clear();
void setFilename(const QString &sPathName);
bool read(ParserCallback pc, void *user);
bool write();
bool write(bool fCopyToParent = false);
QFileDevice::FileError error() {return fe;}

Section &section(QString s);
Expand Down
2 changes: 1 addition & 1 deletion machineeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void MachineEditor::saveToIni()
psect->setValue(sStepsPerMm, ui->dsbBStepsPer->value(), pmachine->b.steps_per_mm, 31);
psect->setValue(sMaxFeedrate, ui->dsbBMaxFeedrate->value(), pmachine->b.max_feedrate, 0);

ie.write();
ie.write(true);
}

void MachineEditor::onRestoreDefaultsClicked()
Expand Down
31 changes: 14 additions & 17 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static void setPathForAppDir(bool fRemove)
if (sPath.isEmpty())
settings.setValue("PATH", a.applicationDirPath());
else if (!sPath.contains(a.applicationDirPath()))
settings.setValue("PATH", sPath + ";" + a.applicationDirPath());
settings.setValue("PATH", a.applicationDirPath() + ";" + sPath);
else
return;
}
Expand Down Expand Up @@ -124,39 +124,36 @@ int main(int argc, char *argv[])

if (clp.isSet(cloInstall)) {
setPathForAppDir(false);
QMessageBox mbox;
mbox.setText(QString("--squirrel-install %1").arg(clp.value(cloInstall)));
mbox.exec();
runUpdate("--createShortcut=GpxUi.exe", false);
return 0;
}
else if(clp.isSet(cloUpdated)) {
// TODO copy *.ini from the obsolete folder
QDir dirSrc = GpxUiInfo::iniLocation();
QDir dirDest = dirSrc;
dirSrc.cdUp();

QStringList slFilters;
slFilters << "*.ini";

QStringList sl = dirSrc.entryList(slFilters);
int is = sl.size();
while (is--) {
QFile::copy(dirSrc.absoluteFilePath(sl[is]), dirDest.absoluteFilePath(sl[is]));
}

setPathForAppDir(false);
QMessageBox mbox;
mbox.setText(QString("--squirrel-updated %1").arg(clp.value(cloUpdated)));
mbox.exec();
return 0;
}
else if (clp.isSet(cloObsolete)) {
setPathForAppDir(true);
QMessageBox mbox;
mbox.setText(QString("--squirrel-obsolete %1").arg(clp.value(cloObsolete)));
mbox.exec();
return 0;
}
else if (clp.isSet(cloUninstall)) {
runUpdate("--removeShortcut=GpxUi.exe", true);
setPathForAppDir(true);
QMessageBox mbox;
mbox.setText(QString("--squirrel-uninstall %1").arg(clp.value(cloUninstall)));
mbox.exec();
return 0;
}
else if (clp.isSet(cloFirstRun)) {
QMessageBox mbox;
mbox.setText(QString("--squirrel-firstrun %1").arg(clp.value(cloFirstRun)));
mbox.exec();
}
else {
clp.showHelp();
Expand Down
2 changes: 1 addition & 1 deletion mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void MainWindow::saveToIni()
psect->setValue("active_temperature", ui->sbRightTemp->value(), 0);
psect->setValue("standby_temperature", ui->sbRightStandby->value(), 0);

ie.write();
ie.write(true);
}

void MainWindow::on_btnDefaults_clicked()
Expand Down

0 comments on commit 05d3523

Please sign in to comment.