mirror of https://github.com/mgba-emu/mgba.git
Updater: Add support for appimage
This commit is contained in:
parent
ccbb44e95a
commit
61bc17953b
|
@ -947,7 +947,7 @@ if(BUILD_OPENEMU)
|
|||
install(TARGETS ${BINARY_NAME}-openemu LIBRARY DESTINATION ${OE_LIBDIR} COMPONENT ${BINARY_NAME}.oecoreplugin NAMELINK_SKIP)
|
||||
endif()
|
||||
|
||||
if(BUILD_QT AND (WIN32 OR APPLE))
|
||||
if(BUILD_QT AND (WIN32 OR APPLE OR CMAKE_SYSTEM_NAME STREQUAL "Linux"))
|
||||
set(BUILD_UPDATER ON)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -173,25 +173,73 @@ int main(int argc, char* argv[]) {
|
|||
prefix = false;
|
||||
needsUnmount = true;
|
||||
#endif
|
||||
} else {
|
||||
} else if (strcmp(extension, "appimage") != 0) {
|
||||
archive = VDirOpenArchive(updateArchive);
|
||||
}
|
||||
if (!archive) {
|
||||
puts("Cannot open update archive");
|
||||
} else {
|
||||
if (archive) {
|
||||
puts("Extracting update");
|
||||
if (extractArchive(archive, root, prefix)) {
|
||||
puts("Complete");
|
||||
const char* command = mUpdateGetCommand(&config);
|
||||
strlcpy(bin, command, sizeof(bin));
|
||||
ok = 0;
|
||||
mUpdateDeregister(&config);
|
||||
} else {
|
||||
puts("An error occurred");
|
||||
}
|
||||
archive->close(archive);
|
||||
unlink(updateArchive);
|
||||
}
|
||||
#ifdef __linux__
|
||||
else if (strcmp(extension, "appimage") == 0) {
|
||||
const char* command = mUpdateGetCommand(&config);
|
||||
strlcpy(bin, command, sizeof(bin));
|
||||
if (rename(updateArchive, bin) < 0) {
|
||||
if (errno == EXDEV) {
|
||||
// Cross-dev, need to copy manually
|
||||
int infd = open(updateArchive, O_RDONLY);
|
||||
int outfd = -1;
|
||||
if (infd >= 0) {
|
||||
ok = 2;
|
||||
} else {
|
||||
outfd = open(bin, O_CREAT | O_WRONLY | O_TRUNC, 0755);
|
||||
}
|
||||
if (outfd < 0) {
|
||||
ok = 2;
|
||||
} else {
|
||||
uint8_t buffer[2048];
|
||||
ssize_t size;
|
||||
while ((size = read(infd, buffer, sizeof(buffer))) > 0) {
|
||||
if (write(outfd, buffer, size) < size) {
|
||||
ok = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (size < 0) {
|
||||
ok = 2;
|
||||
}
|
||||
close(outfd);
|
||||
close(infd);
|
||||
}
|
||||
if (ok == 2) {
|
||||
puts("Cannot move update over old file");
|
||||
}
|
||||
} else {
|
||||
puts("Cannot move update over old file");
|
||||
}
|
||||
} else {
|
||||
ok = 0;
|
||||
}
|
||||
if (ok == 0) {
|
||||
chmod(bin, 0755);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
puts("Cannot open update archive");
|
||||
}
|
||||
if (ok == 0) {
|
||||
puts("Complete");
|
||||
const char* command = mUpdateGetCommand(&config);
|
||||
strlcpy(bin, command, sizeof(bin));
|
||||
mUpdateDeregister(&config);
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
if (needsUnmount) {
|
||||
char* args[] = {"hdiutil", "detach", devpath, NULL};
|
||||
|
|
|
@ -24,13 +24,23 @@ ApplicationUpdatePrompt::ApplicationUpdatePrompt(QWidget* parent)
|
|||
ApplicationUpdater* updater = GBAApp::app()->updater();
|
||||
ApplicationUpdater::UpdateInfo info = updater->updateInfo();
|
||||
QString updateText(tr("An update to %1 is available.\n").arg(QLatin1String(projectName)));
|
||||
bool available;
|
||||
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
||||
updateText += tr("\nDo you want to download and install it now? You will need to restart the emulator when the download is complete.");
|
||||
m_okDownload = connect(m_ui.buttonBox, &QDialogButtonBox::accepted, this, &ApplicationUpdatePrompt::startUpdate);
|
||||
available = true;
|
||||
#elif defined(Q_OS_LINUX)
|
||||
QString path = QCoreApplication::applicationDirPath();
|
||||
QFileInfo finfo(path + "/../../AppRun");
|
||||
available = finfo.exists() && finfo.isExecutable();
|
||||
#else
|
||||
updateText += tr("\nAuto-update is not available on this platform. If you wish to update you will need to do it manually.");
|
||||
connect(m_ui.buttonBox, &QDialogButtonBox::accepted, this, &QWidget::close);
|
||||
available = false;
|
||||
#endif
|
||||
if (available) {
|
||||
updateText += tr("\nDo you want to download and install it now? You will need to restart the emulator when the download is complete.");
|
||||
m_okDownload = connect(m_ui.buttonBox, &QDialogButtonBox::accepted, this, &ApplicationUpdatePrompt::startUpdate);
|
||||
} else {
|
||||
updateText += tr("\nAuto-update is not available on this platform. If you wish to update you will need to do it manually.");
|
||||
connect(m_ui.buttonBox, &QDialogButtonBox::accepted, this, &QWidget::close);
|
||||
}
|
||||
m_ui.text->setText(updateText);
|
||||
m_ui.details->setText(tr("Current version: %1\nNew version: %2\nDownload size: %3")
|
||||
.arg(QLatin1String(projectVersion))
|
||||
|
|
|
@ -151,6 +151,8 @@ const char* ApplicationUpdater::platform() {
|
|||
#endif
|
||||
#elif defined(Q_OS_MACOS)
|
||||
return "osx";
|
||||
#elif defined(Q_OS_LINUX) && defined(__x86_64__)
|
||||
return "appimage-x64";
|
||||
#else
|
||||
// Return one that will be up to date, but we can't download
|
||||
return "win64";
|
||||
|
|
Loading…
Reference in New Issue