Skip to content

Commit

Permalink
NOISSUE further changes towards system installed layout
Browse files Browse the repository at this point in the history
  • Loading branch information
peterix committed May 24, 2023
1 parent 9213d42 commit d336f75
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 72 deletions.
1 change: 1 addition & 0 deletions buildconfig/BuildConfig.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Config BuildConfig;
Config::Config()
{
// Name and copyright
LAUNCHER_FSNAME = "@Launcher_FSName@";
LAUNCHER_NAME = "@Launcher_Name@";
LAUNCHER_DISPLAYNAME = "@Launcher_DisplayName@";
LAUNCHER_COPYRIGHT = "@Launcher_Copyright@";
Expand Down
1 change: 1 addition & 0 deletions buildconfig/BuildConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Config
{
public:
Config();
QString LAUNCHER_FSNAME;
QString LAUNCHER_NAME;
QString LAUNCHER_DISPLAYNAME;
QString LAUNCHER_COPYRIGHT;
Expand Down
68 changes: 68 additions & 0 deletions cmake/QtCommon.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
macro(fix_project_version)
if (NOT PROJECT_VERSION_PATCH)
set(PROJECT_VERSION_PATCH 0)
endif()

if (NOT PROJECT_VERSION_TWEAK)
set(PROJECT_VERSION_TWEAK 0)
endif()
endmacro()

macro(add_project_meta FILES_TO_INCLUDE)
if (NOT RESOURCE_FOLDER)
set(RESOURCE_FOLDER branding)
endif()

if (NOT ICON_NAME)
set(ICON_NAME ${PROJECT_NAME})
endif()

if (APPLE)
set(ICON_FILE branding/${ICON_NAME}.icns)
elseif (WIN32)
set(ICON_FILE branding/${ICON_NAME}.ico)
endif()

if (WIN32)
set(WIN_MANIFEST_IDENTIFIER ${IDENTIFIER})
configure_file("${PROJECT_SOURCE_DIR}/cmake/windows_metafile.rc.in"
"windows_metafile.rc"
)
configure_file("${PROJECT_SOURCE_DIR}/cmake/windows.manifest.in"
"windows.manifest"
)
set(RES_FILES "windows_metafile.rc")
set(CMAKE_RC_COMPILER_INIT windres)
ENABLE_LANGUAGE(RC)
SET(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
endif()

if (APPLE)
set_source_files_properties(${ICON_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)

# Identify MacOS bundle
set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
set(MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION})
set(MACOSX_BUNDLE_LONG_VERSION_STRING ${PROJECT_VERSION})
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
set(MACOSX_BUNDLE_COPYRIGHT ${COPYRIGHT})
set(MACOSX_BUNDLE_GUI_IDENTIFIER ${IDENTIFIER})
set(MACOSX_BUNDLE_ICON_FILE ${ICON_NAME})
endif()

if (APPLE)
set(${FILES_TO_INCLUDE} ${ICON_FILE})
elseif (WIN32)
set(${FILES_TO_INCLUDE} ${RES_FILES})
endif()
endmacro()

macro(init_os_bundle)
if (APPLE)
set(OS_BUNDLE MACOSX_BUNDLE)
elseif (WIN32)
set(OS_BUNDLE WIN32)
endif()
endmacro()

init_os_bundle()
31 changes: 31 additions & 0 deletions cmake/windows.manifest.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<assemblyIdentity name="@WIN_MANIFEST_IDENTIFIER@" type="amd64" version="@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@.@PROJECT_VERSION_TWEAK@" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="amd64" publicKeyToken="6595b64144ccf1df" language="*"/>
</dependentAssembly>
</dependency>
<description>Custom Minecraft launcher for managing multiple installs.</description>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--The ID below indicates app support for Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!--The ID below indicates app support for Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!--The ID below indicates app support for Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!--The ID below indicates app support for Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!--The ID below indicates app support for Windows 10, 11 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
</assembly>
36 changes: 36 additions & 0 deletions cmake/windows_metafile.rc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>

IDI_ICON1 ICON DISCARDABLE "@ICON_FILE@"
1 RT_MANIFEST "windows.manifest"

VS_VERSION_INFO VERSIONINFO
FILEVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@,@PROJECT_VERSION_TWEAK@
PRODUCTVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@,@PROJECT_VERSION_TWEAK@
FILEFLAGS 0x0L
FILEFLAGSMASK 0x3fL
FILEOS 0x00040004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "000004b0"
BEGIN
VALUE "CompanyName", "@COMPANY@"
VALUE "FileDescription", "@DESCRIPTION@"
VALUE "FileVersion", "@PROJECT_VERSION@"
VALUE "LegalCopyright", "@COPYRIGHT@"
VALUE "InternalName", "@PROJECT_NAME@"
VALUE "OriginalFilename", "@PROJECT_NAME@.exe"
VALUE "ProductName", "@PROJECT_NAME@"
VALUE "ProductVersion", "@PROJECT_VERSION@"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0000, 0x04b0 // Unicode
END
END
77 changes: 10 additions & 67 deletions launcher/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static const QLatin1String liveCheckFile("live.check");

using namespace Commandline;

#define MACOS_HINT "If you are on macOS Sierra, you might have to move the app to your /Applications or ~/Applications folder. "\
#define MACOS_HINT "If you are on macOS Sierra or newer, you might have to move the app to your /Applications or ~/Applications folder. "\
"This usually fixes the problem and you can move the application elsewhere afterwards.\n"\
"\n"

Expand Down Expand Up @@ -315,6 +315,8 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
QString adjustedBy;
QString dataPath;
// change folder
// FIXME: Actually implement portable installs again in some way...
constexpr bool portableInstall = false;
QString dirParam = args["dir"].toString();
if (!dirParam.isEmpty())
{
Expand All @@ -323,16 +325,20 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
adjustedBy += "Command line " + dirParam;
dataPath = dirParam;
}
else
else if(portableInstall)
{
#if defined(Q_OS_MAC)
QDir foo(FS::PathCombine(applicationDirPath(), "../../Data"));
dataPath = foo.absolutePath();
adjustedBy += "Fallback to special Mac location " + dataPath;
#else
dataPath = applicationDirPath();
adjustedBy += "Fallback to binary path " + dataPath;
#endif
adjustedBy += "Portable binary path " + dataPath;
}
else {
auto dataLocation = QStandardPaths::writableLocation(QStandardPaths::StandardLocation::GenericDataLocation);
dataPath = FS::PathCombine(dataLocation, BuildConfig.LAUNCHER_FSNAME);
adjustedBy += "Standard data path " + dataPath;
}

if (!FS::ensureFolderPathExists(dataPath))
Expand Down Expand Up @@ -427,69 +433,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
}
}

#if defined(Q_OS_MAC)
// move user data to new location if on macOS and it still exists in Contents/MacOS
QDir fi(applicationDirPath());
QString originalData = fi.absolutePath();
// if the config file exists in Contents/MacOS, then user data is still there and needs to moved
if (QFileInfo::exists(FS::PathCombine(originalData, BuildConfig.LAUNCHER_CONFIGFILE)))
{
if (!QFileInfo::exists(FS::PathCombine(originalData, "dontmovemacdata")))
{
QMessageBox::StandardButton askMoveDialogue;
askMoveDialogue = QMessageBox::question(
nullptr,
BuildConfig.LAUNCHER_DISPLAYNAME,
"Would you like to move application data to a new data location? It will improve the launcher's performance, but if you switch to older versions it will look like instances have disappeared. If you select no, you can migrate later in settings. You should select yes unless you're commonly switching between different versions (eg. develop and stable).",
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes
);
if (askMoveDialogue == QMessageBox::Yes)
{
qDebug() << "On macOS and found config file in old location, moving user data...";
QDir dir;
QStringList dataFiles {
"*.log", // Launcher log files: ${Launcher_Name}-@.log
"accounts.json",
"accounts",
"assets",
"cache",
"icons",
"instances",
"libraries",
"meta",
"metacache",
"mods",
BuildConfig.LAUNCHER_CONFIGFILE,
"themes",
"translations"
};
QDirIterator files(originalData, dataFiles);
while (files.hasNext()) {
QString filePath(files.next());
QString fileName(files.fileName());
if (!dir.rename(filePath, FS::PathCombine(dataPath, fileName)))
{
qWarning() << "Failed to move " << fileName;
}
}
}
else
{
dataPath = originalData;
QDir::setCurrent(dataPath);
QFile file(originalData + "/dontmovemacdata");
file.open(QIODevice::WriteOnly);
}
}
else
{
dataPath = originalData;
QDir::setCurrent(dataPath);
}
}
#endif

/*
* Establish the mechanism for communication with an already running MultiMC that uses the same data path.
* If there is one, tell it what the user actually wanted to do and exit.
Expand Down
2 changes: 1 addition & 1 deletion launcher/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class Application : public QApplication
QString getJarsPath();

/// this is the root of the 'installation'. Used for automatic updates
const QString &root() {
const QString &applicationRoot() {
return m_rootPath;
}

Expand Down
8 changes: 5 additions & 3 deletions launcher/ui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,12 +665,14 @@ class MainWindow::Ui

void retranslateUi(QMainWindow *MainWindow)
{
/*
QString winTitle = tr("%1 - Version %2", "Launcher - Version X").arg(BuildConfig.LAUNCHER_DISPLAYNAME, BuildConfig.printableVersionString());
if (!BuildConfig.BUILD_PLATFORM.isEmpty())
{
winTitle += tr(" on %1", "on platform, as in operating system").arg(BuildConfig.BUILD_PLATFORM);
}
MainWindow->setWindowTitle(winTitle);
*/
// all the actions
for(auto * item: all_actions)
{
Expand Down Expand Up @@ -1329,9 +1331,9 @@ void MainWindow::downloadUpdates(GoUpdate::Status status)
}
qDebug() << "Downloading updates.";
ProgressDialog updateDlg(this);
status.rootPath = APPLICATION->root();
status.rootPath = APPLICATION->applicationRoot();

auto dlPath = FS::PathCombine(APPLICATION->root(), "update", "XXXXXX");
auto dlPath = FS::PathCombine(APPLICATION->applicationRoot(), "update", "XXXXXX");
if (!FS::ensureFilePathExists(dlPath))
{
CustomMessageBox::selectable(this, tr("Error"), tr("Couldn't create folder for update downloads:\n%1").arg(dlPath), QMessageBox::Warning)->show();
Expand All @@ -1345,7 +1347,7 @@ void MainWindow::downloadUpdates(GoUpdate::Status status)
* or the update fails (and the control leaves this scope).
*/
APPLICATION->updateIsRunning(true);
UpdateController update(this, APPLICATION->root(), updateTask.updateFilesDir(), updateTask.operations());
UpdateController update(this, APPLICATION->applicationRoot(), updateTask.updateFilesDir(), updateTask.operations());
update.installUpdates();
APPLICATION->updateIsRunning(false);
}
Expand Down
3 changes: 2 additions & 1 deletion notsecrets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ set(Launcher_CommonName "DevLauncher")
set(Launcher_Copyright "MultiMC Contributors" PARENT_SCOPE)
set(Launcher_Domain "multimc.org" PARENT_SCOPE)
set(Launcher_Name "${Launcher_CommonName}" PARENT_SCOPE)
set(Launcher_FSName "devlauncher" PARENT_SCOPE)
set(Launcher_DisplayName "${Launcher_CommonName} 5" PARENT_SCOPE)
set(Launcher_UserAgent "${Launcher_CommonName}/5.0" PARENT_SCOPE)
set(Launcher_ConfigFile "devlauncher.cfg" PARENT_SCOPE)
set(Launcher_ConfigFile "${Launcher_FSName}.cfg" PARENT_SCOPE)
set(Launcher_Git "https://github.com/MultiMC/Launcher" PARENT_SCOPE)

set(Launcher_Branding_ICNS "notsecrets/Launcher.icns" PARENT_SCOPE)
Expand Down

0 comments on commit d336f75

Please sign in to comment.