Skip to content

Commit

Permalink
Updater: Deleting the installed package afterwards
Browse files Browse the repository at this point in the history
The requested removal of the installed package occurs when the engine
is next started.
  • Loading branch information
skyjake committed Jun 8, 2012
1 parent b303cd4 commit 80266f3
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 1 deletion.
28 changes: 28 additions & 0 deletions doomsday/engine/portable/src/updater.cpp
Expand Up @@ -117,6 +117,23 @@ struct Updater::Instance
Instance(Updater* up) : self(up), network(0), download(0)
{
network = new QNetworkAccessManager(self);

// Delete a package installed earlier?
UpdaterSettings st;
if(st.deleteAfterUpdate())
{
de::String p = st.pathToDeleteAtStartup();
if(!p.isEmpty())
{
QFile file(p);
if(file.exists())
{
LOG_INFO("Deleting previously installed package: %s") << p;
file.remove();
}
}
}
st.setPathToDeleteAtStartup("");
}

~Instance()
Expand Down Expand Up @@ -316,6 +333,17 @@ struct Updater::Instance
atexit(runInstallerCommand);
#endif

// If requested, delete the downloaded package afterwards. Currently
// this occurs the next time when the engine is launched; on some
// platforms it could be incorporated into the reinstall procedure.
// (This will work better when there is no more separate frontend, as
// the engine is restarted after the install.)
UpdaterSettings st;
if(st.deleteAfterUpdate())
{
st.setPathToDeleteAtStartup(distribPackagePath);
}

Sys_Quit();
}
};
Expand Down
18 changes: 18 additions & 0 deletions doomsday/engine/portable/src/updater/updatersettings.cpp
Expand Up @@ -10,6 +10,7 @@
#define STK_ONLY_MANUAL "updater/onlyManually"
#define STK_DELETE "updater/delete"
#define STK_DOWNLOAD_PATH "updater/downloadPath"
#define STK_DELETE_PATH "updater/deleteAtStartup"

UpdaterSettings::UpdaterSettings()
{}
Expand Down Expand Up @@ -45,6 +46,18 @@ bool UpdaterSettings::deleteAfterUpdate() const
return QSettings().value(STK_DELETE, true).toBool();
}

de::String UpdaterSettings::pathToDeleteAtStartup() const
{
de::String p = de::String::fromNativePath(QSettings().value(STK_DELETE_PATH).toString());
de::String ext = p.fileNameExtension();
if(p.fileName().startsWith("doomsday") && (ext == ".exe" || ext == ".deb" || ext == ".dmg"))
{
return p;
}
// Doesn't look valid.
return "";
}

bool UpdaterSettings::isDefaultDownloadPath() const
{
de::String path = downloadPath();
Expand Down Expand Up @@ -100,6 +113,11 @@ void UpdaterSettings::useDefaultDownloadPath()
setDownloadPath(defaultDownloadPath());
}

void UpdaterSettings::setPathToDeleteAtStartup(de::String deletePath)
{
QSettings().setValue(STK_DELETE_PATH, deletePath);
}

de::String UpdaterSettings::defaultDownloadPath()
{
return QDesktopServices::storageLocation(QDesktopServices::TempLocation);
Expand Down
2 changes: 2 additions & 0 deletions doomsday/engine/portable/src/updater/updatersettings.h
Expand Up @@ -30,6 +30,7 @@ class UpdaterSettings
bool deleteAfterUpdate() const;
bool isDefaultDownloadPath() const;
de::String downloadPath() const;
de::String pathToDeleteAtStartup() const;

void setFrequency(Frequency freq);
void setChannel(Channel channel);
Expand All @@ -38,6 +39,7 @@ class UpdaterSettings
void setDeleteAfterUpdate(bool deleteAfter);
void setDownloadPath(de::String downloadPath);
void useDefaultDownloadPath();
void setPathToDeleteAtStartup(de::String deletePath);

static de::String defaultDownloadPath();
};
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/window.cpp
Expand Up @@ -386,7 +386,7 @@ struct ddwindow_s
case DDWA_FULLSCREEN:
if(IS_NONZERO(attribs[i]) != IS_NONZERO(checkFlag(DDWF_FULLSCREEN)))
{
if(IS_NONZERO(attribs[i]) && Updater_IsDownloadInProgress())
if(attribs[i] && Updater_IsDownloadInProgress())
{
// Can't go to fullscreen when downloading.
return false;
Expand Down
7 changes: 7 additions & 0 deletions doomsday/libdeng2/include/de/data/string.h
Expand Up @@ -199,6 +199,13 @@ class DENG2_PUBLIC String : public QString
*/
static String fromLatin1(const IByteArray& byteArray);

/**
* Builds a String out of a native path. Path separators are converted to slashes.
* @param nativePath Native path.
* @return String with a platform-independent path.
*/
static String fromNativePath(const de::String& nativePath);

static dint compareWithCase(const QChar* a, const QChar* b, dsize count);

/**
Expand Down
9 changes: 9 additions & 0 deletions doomsday/libdeng2/src/data/string.cpp
Expand Up @@ -501,3 +501,12 @@ String String::fromLatin1(const IByteArray& byteArray)
{
return QString::fromLatin1(reinterpret_cast<const char*>(Block(byteArray).data()));
}

String String::fromNativePath(const String& nativePath)
{
String s = nativePath;
#ifdef Q_OS_WIN32
s.replace("\\", "/");
#endif
return s;
}

0 comments on commit 80266f3

Please sign in to comment.