mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-17 21:11:39 +00:00
Fixed: Create links under Windows
This commit is contained in:
parent
2a6989c9b5
commit
230fb82bc7
7 changed files with 138 additions and 26 deletions
|
@ -608,9 +608,24 @@ bool CConfigFile::foundTemporaryFiles(const QString &directory) const
|
||||||
|
|
||||||
bool CConfigFile::shouldCreateDesktopShortcut() const
|
bool CConfigFile::shouldCreateDesktopShortcut() const
|
||||||
{
|
{
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
const CProfile &profile = getProfile();
|
const CProfile &profile = getProfile();
|
||||||
|
|
||||||
return profile.desktopShortcut && !QFile::exists(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/Ryzom.lnk");
|
return profile.desktopShortcut && !NLMISC::CFile::isExists(qToUtf8(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/Ryzom.lnk"));
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CConfigFile::shouldCreateMenuShortcut() const
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
const CProfile &profile = getProfile();
|
||||||
|
|
||||||
|
return profile.menuShortcut && !NLMISC::CFile::isExists(qToUtf8(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/Ryzom/Ryzom.lnk"));
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CConfigFile::getProfileClientFullPath(int profileIndex) const
|
QString CConfigFile::getProfileClientFullPath(int profileIndex) const
|
||||||
|
@ -799,8 +814,12 @@ OperationStep CConfigFile::getInstallNextStep() const
|
||||||
|
|
||||||
if (shouldCreateDesktopShortcut())
|
if (shouldCreateDesktopShortcut())
|
||||||
{
|
{
|
||||||
// TODO: check they point to getClientFullPath()
|
return CreateDesktopShortcut;
|
||||||
return CreateShortcuts;
|
}
|
||||||
|
|
||||||
|
if (shouldCreateMenuShortcut())
|
||||||
|
{
|
||||||
|
return CreateMenuShortcut;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
|
|
@ -153,6 +153,7 @@ public:
|
||||||
|
|
||||||
bool foundTemporaryFiles(const QString &directory) const;
|
bool foundTemporaryFiles(const QString &directory) const;
|
||||||
bool shouldCreateDesktopShortcut() const;
|
bool shouldCreateDesktopShortcut() const;
|
||||||
|
bool shouldCreateMenuShortcut() const;
|
||||||
|
|
||||||
// installation choices
|
// installation choices
|
||||||
bool use64BitsClient() const;
|
bool use64BitsClient() const;
|
||||||
|
|
|
@ -62,7 +62,8 @@ enum OperationStep
|
||||||
CopyInstaller,
|
CopyInstaller,
|
||||||
UninstallOldClient,
|
UninstallOldClient,
|
||||||
CreateProfile,
|
CreateProfile,
|
||||||
CreateShortcuts,
|
CreateDesktopShortcut,
|
||||||
|
CreateMenuShortcut,
|
||||||
CreateAddRemoveEntry,
|
CreateAddRemoveEntry,
|
||||||
Done
|
Done
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "configfile.h"
|
#include "configfile.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "profilesmodel.h"
|
#include "profilesmodel.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include "filescopier.h"
|
#include "filescopier.h"
|
||||||
#include "filesextractor.h"
|
#include "filesextractor.h"
|
||||||
|
@ -167,8 +168,12 @@ void COperationDialog::processInstallNextStep()
|
||||||
createDefaultProfile();
|
createDefaultProfile();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CreateShortcuts:
|
case CreateDesktopShortcut:
|
||||||
createDefaultShortcuts();
|
createClientDesktopShortcut(0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CreateMenuShortcut:
|
||||||
|
createClientMenuShortcut(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CreateAddRemoveEntry:
|
case CreateAddRemoveEntry:
|
||||||
|
@ -673,6 +678,8 @@ void COperationDialog::copyInstaller()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: create shortcuts for installer
|
||||||
|
|
||||||
emit done();
|
emit done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -745,14 +752,42 @@ bool COperationDialog::createDefaultProfile()
|
||||||
profile.name = QString("Ryzom (%1)").arg(server.name);
|
profile.name = QString("Ryzom (%1)").arg(server.name);
|
||||||
profile.server = server.id;
|
profile.server = server.id;
|
||||||
profile.comments = "Default profile created by Ryzom Installer";
|
profile.comments = "Default profile created by Ryzom Installer";
|
||||||
|
profile.desktopShortcut = false;
|
||||||
|
profile.menuShortcut = false;
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
// C:\Users\Public\Desktop
|
QStringList paths;
|
||||||
profile.desktopShortcut = QFile::exists(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/Ryzom.lnk");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// TODO
|
// desktop
|
||||||
// profile.menuShortcut
|
|
||||||
|
// Windows XP
|
||||||
|
paths << "C:/Documents and Settings/All Users/Desktop";
|
||||||
|
// since Windows Vista
|
||||||
|
paths << "C:/Users/Public/Desktop";
|
||||||
|
// new location
|
||||||
|
paths << QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||||
|
|
||||||
|
foreach(const QString &path, paths)
|
||||||
|
{
|
||||||
|
if (QFile::exists(path + "/Ryzom.lnk")) profile.desktopShortcut = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
paths.clear();
|
||||||
|
|
||||||
|
// start menu
|
||||||
|
|
||||||
|
// Windows XP
|
||||||
|
paths << "C:/Documents and Settings/All Users/Start Menu/Programs";
|
||||||
|
// since Windows Vista
|
||||||
|
paths << "C:/ProgramData/Microsoft/Windows/Start Menu/Programs";
|
||||||
|
// new location
|
||||||
|
paths << QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
|
||||||
|
|
||||||
|
foreach(const QString &path, paths)
|
||||||
|
{
|
||||||
|
if (QFile::exists(path + "/Ryzom/Ryzom.lnk")) profile.menuShortcut = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
config->addProfile(profile);
|
config->addProfile(profile);
|
||||||
config->save();
|
config->save();
|
||||||
|
@ -762,11 +797,51 @@ bool COperationDialog::createDefaultProfile()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool COperationDialog::createDefaultShortcuts()
|
bool COperationDialog::createClientDesktopShortcut(int profileIndex)
|
||||||
{
|
{
|
||||||
CConfigFile *config = CConfigFile::getInstance();
|
CConfigFile *config = CConfigFile::getInstance();
|
||||||
|
|
||||||
CServer server = config->getServer();
|
const CProfile &profile = config->getProfile(profileIndex);
|
||||||
|
const CServer &server = config->getServer(profile.server);
|
||||||
|
|
||||||
|
m_currentOperation = tr("Create desktop shortcut for profile %1").arg(profile.id);
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
if (profile.desktopShortcut)
|
||||||
|
{
|
||||||
|
QString shortcut = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/Ryzom.lnk";
|
||||||
|
CreateLink(config->getProfileClientFullPath(), shortcut, QString("--profile %1 %2").arg(profile.id).arg(profile.arguments), server.getDirectory(), "Default Ryzom client");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
emit done();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool COperationDialog::createClientMenuShortcut(int profileIndex)
|
||||||
|
{
|
||||||
|
CConfigFile *config = CConfigFile::getInstance();
|
||||||
|
|
||||||
|
const CProfile &profile = config->getProfile(profileIndex);
|
||||||
|
const CServer &server = config->getServer(profile.server);
|
||||||
|
|
||||||
|
m_currentOperation = tr("Create menu shortcut for profile %1").arg(profile.id);
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
if (profile.menuShortcut)
|
||||||
|
{
|
||||||
|
QString path = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/Ryzom";
|
||||||
|
|
||||||
|
QDir dir;
|
||||||
|
|
||||||
|
if (dir.mkpath(path))
|
||||||
|
{
|
||||||
|
QString shortcut = path + "/Ryzom.lnk";
|
||||||
|
CreateLink(config->getProfileClientFullPath(), shortcut, QString("--profile %1 %2").arg(profile.id).arg(profile.arguments), server.getDirectory(), "Default Ryzom client");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
emit done();
|
emit done();
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,8 @@ protected:
|
||||||
void copyInstaller();
|
void copyInstaller();
|
||||||
void uninstallOldClient();
|
void uninstallOldClient();
|
||||||
bool createDefaultProfile();
|
bool createDefaultProfile();
|
||||||
bool createDefaultShortcuts();
|
bool createClientDesktopShortcut(int profileIndex);
|
||||||
|
bool createClientMenuShortcut(int profileIndex);
|
||||||
bool createAddRemoveEntry();
|
bool createAddRemoveEntry();
|
||||||
bool deleteAddRemoveEntry();
|
bool deleteAddRemoveEntry();
|
||||||
void deleteComponentsServers();
|
void deleteComponentsServers();
|
||||||
|
|
|
@ -111,22 +111,22 @@ wchar_t* qToWide(const QString &str)
|
||||||
// Shell link, stored in the Comment field of the link
|
// Shell link, stored in the Comment field of the link
|
||||||
// properties.
|
// properties.
|
||||||
|
|
||||||
HRESULT CreateLink(const QString &pathObj, const QString &pathLink, const QString &desc)
|
bool CreateLink(const QString &pathObj, const QString &pathLink, const QString &arguments, const QString &workingDir, const QString &desc)
|
||||||
{
|
{
|
||||||
IShellLinkW* psl;
|
IShellLinkW* psl;
|
||||||
|
|
||||||
// Get a pointer to the IShellLink interface. It is assumed that CoInitialize
|
// Get a pointer to the IShellLink interface. It is assumed that CoInitialize
|
||||||
// has already been called.
|
// has already been called.
|
||||||
HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
|
HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (LPVOID*)&psl);
|
||||||
if (SUCCEEDED(hres))
|
if (SUCCEEDED(hres))
|
||||||
{
|
{
|
||||||
IPersistFile* ppf;
|
IPersistFile* ppf;
|
||||||
|
|
||||||
// Set the path to the shortcut target and add the description.
|
// Set the path to the shortcut target and add the description.
|
||||||
psl->SetPath(qToWide(pathObj));
|
psl->SetPath(qToWide(QDir::toNativeSeparators(pathObj)));
|
||||||
psl->SetDescription(qToWide(desc));
|
psl->SetDescription(qToWide(desc));
|
||||||
psl->SetArguments(L"--profil ");
|
psl->SetArguments(qToWide(arguments));
|
||||||
psl->SetWorkingDirectory(L"");
|
psl->SetWorkingDirectory(qToWide(QDir::toNativeSeparators(workingDir)));
|
||||||
|
|
||||||
// Query IShellLink for the IPersistFile interface, used for saving the
|
// Query IShellLink for the IPersistFile interface, used for saving the
|
||||||
// shortcut in persistent storage.
|
// shortcut in persistent storage.
|
||||||
|
@ -138,12 +138,12 @@ HRESULT CreateLink(const QString &pathObj, const QString &pathLink, const QStrin
|
||||||
// for success.
|
// for success.
|
||||||
|
|
||||||
// Save the link by calling IPersistFile::Save.
|
// Save the link by calling IPersistFile::Save.
|
||||||
hres = ppf->Save(qToWide(pathLink), TRUE);
|
hres = ppf->Save(qToWide(QDir::toNativeSeparators(pathLink)), TRUE);
|
||||||
ppf->Release();
|
ppf->Release();
|
||||||
}
|
}
|
||||||
psl->Release();
|
psl->Release();
|
||||||
}
|
}
|
||||||
return hres;
|
return SUCCEEDED(hres);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolveIt - Uses the Shell's IShellLink and IPersistFile interfaces
|
// ResolveIt - Uses the Shell's IShellLink and IPersistFile interfaces
|
||||||
|
@ -163,7 +163,7 @@ HRESULT CreateLink(const QString &pathObj, const QString &pathLink, const QStrin
|
||||||
// Shell link, stored in the Comment field of the link
|
// Shell link, stored in the Comment field of the link
|
||||||
// properties.
|
// properties.
|
||||||
|
|
||||||
HRESULT ResolveIt(HWND hwnd, const QString &linkFile, QString &path)
|
bool ResolveLink(const QWidget &window, const QString &linkFile, QString &path)
|
||||||
{
|
{
|
||||||
IShellLinkW* psl;
|
IShellLinkW* psl;
|
||||||
WIN32_FIND_DATAW wfd;
|
WIN32_FIND_DATAW wfd;
|
||||||
|
@ -186,12 +186,12 @@ HRESULT ResolveIt(HWND hwnd, const QString &linkFile, QString &path)
|
||||||
// for success.
|
// for success.
|
||||||
|
|
||||||
// Load the shortcut.
|
// Load the shortcut.
|
||||||
hres = ppf->Load(qToWide(linkFile), STGM_READ);
|
hres = ppf->Load(qToWide(QDir::toNativeSeparators(linkFile)), STGM_READ);
|
||||||
|
|
||||||
if (SUCCEEDED(hres))
|
if (SUCCEEDED(hres))
|
||||||
{
|
{
|
||||||
// Resolve the link.
|
// Resolve the link.
|
||||||
hres = psl->Resolve(hwnd, 0);
|
hres = psl->Resolve((HWND)window.winId(), 0);
|
||||||
|
|
||||||
if (SUCCEEDED(hres))
|
if (SUCCEEDED(hres))
|
||||||
{
|
{
|
||||||
|
@ -210,7 +210,7 @@ HRESULT ResolveIt(HWND hwnd, const QString &linkFile, QString &path)
|
||||||
if (SUCCEEDED(hres))
|
if (SUCCEEDED(hres))
|
||||||
{
|
{
|
||||||
// Handle success
|
// Handle success
|
||||||
path = qFromWide(szGotPath);
|
path = QDir::fromNativeSeparators(qFromWide(szGotPath));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -227,7 +227,19 @@ HRESULT ResolveIt(HWND hwnd, const QString &linkFile, QString &path)
|
||||||
psl->Release();
|
psl->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
return hres;
|
return SUCCEEDED(hres);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
bool CreateLink(const QString &pathObj, const QString &pathLink, const QString &arguments, const QString &workingDir, const QString &desc)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ResolveLink(const QWidget &window, const QString &pathLink, QString &pathObj)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -48,4 +48,7 @@ QString qFromWide(const wchar_t *str);
|
||||||
|
|
||||||
wchar_t* qToWide(const QString &str);
|
wchar_t* qToWide(const QString &str);
|
||||||
|
|
||||||
|
bool CreateLink(const QString &pathObj, const QString &pathLink, const QString &arguments, const QString &workingDir, const QString &desc);
|
||||||
|
bool ResolveLink(const QWidget &window, const QString &pathLink, QString &pathObj);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue