diff options
author | Andrew <forkk@forkk.net> | 2013-02-25 14:44:36 -0600 |
---|---|---|
committer | Andrew <forkk@forkk.net> | 2013-02-25 14:44:36 -0600 |
commit | 4ca35a760dfc53fd69f0f2030868ebeda250ed59 (patch) | |
tree | 1fa312da2d051676830e222b3959a100a2fa6e05 /libutil/src/userutils.cpp | |
parent | b56b819c35843db0d135a5bbbee5fc9916bd06df (diff) | |
download | PrismLauncher-4ca35a760dfc53fd69f0f2030868ebeda250ed59.tar.gz PrismLauncher-4ca35a760dfc53fd69f0f2030868ebeda250ed59.tar.bz2 PrismLauncher-4ca35a760dfc53fd69f0f2030868ebeda250ed59.zip |
Fixed a lot of MSVC problems
Diffstat (limited to 'libutil/src/userutils.cpp')
-rw-r--r-- | libutil/src/userutils.cpp | 158 |
1 files changed, 84 insertions, 74 deletions
diff --git a/libutil/src/userutils.cpp b/libutil/src/userutils.cpp index f3778d08..b70841ed 100644 --- a/libutil/src/userutils.cpp +++ b/libutil/src/userutils.cpp @@ -20,94 +20,104 @@ bool called_coinit = false; -HRESULT CreateLink(LPCSTR linkPath, LPCWSTR targetPath, LPCWSTR args) +HRESULT CreateLink(LPCSTR linkPath, LPCSTR targetPath, LPCSTR args) { - HRESULT hres; - - if (!called_coinit) - { - hres = CoInitialize(NULL); - called_coinit = true; - - if (!SUCCEEDED(hres)) - { - qWarning("Failed to initialize COM. Error 0x%08X", hres); - return hres; - } - } - - - IShellLink* link; - hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&link); - - if (SUCCEEDED(hres)) - { - IPersistFile* persistFile; - - link->SetPath(targetPath); - link->SetArguments(args); - - hres = link->QueryInterface(IID_IPersistFile, (LPVOID*)&persistFile); - if (SUCCEEDED(hres)) - { - WCHAR wstr[MAX_PATH]; - - MultiByteToWideChar(CP_ACP, 0, linkPath, -1, wstr, MAX_PATH); - - hres = persistFile->Save(wstr, TRUE); - persistFile->Release(); - } - link->Release(); - } - return hres; + HRESULT hres; + + if (!called_coinit) + { + hres = CoInitialize(NULL); + called_coinit = true; + + if (!SUCCEEDED(hres)) + { + qWarning("Failed to initialize COM. Error 0x%08X", hres); + return hres; + } + } + + + IShellLink* link; + hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&link); + + if (SUCCEEDED(hres)) + { + IPersistFile* persistFile; + + link->SetPath(targetPath); + link->SetArguments(args); + + hres = link->QueryInterface(IID_IPersistFile, (LPVOID*)&persistFile); + if (SUCCEEDED(hres)) + { + WCHAR wstr[MAX_PATH]; + + MultiByteToWideChar(CP_ACP, 0, linkPath, -1, wstr, MAX_PATH); + + hres = persistFile->Save(wstr, TRUE); + persistFile->Release(); + } + link->Release(); + } + return hres; } #endif QString Util::getDesktopDir() { - return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); } // Cross-platform Shortcut creation bool Util::createShortCut(QString location, QString dest, QStringList args, QString name, QString icon) { #if LINUX - location = PathCombine(location, name + ".desktop"); - qDebug("location: %s", qPrintable(location)); - - QFile f(location); - f.open(QIODevice::WriteOnly | QIODevice::Text); - QTextStream stream(&f); - - QString argstring; - if (!args.empty()) - argstring = " '" + args.join("' '") + "'"; - - stream << "[Desktop Entry]" << "\n"; - stream << "Type=Application" << "\n"; - stream << "TryExec=" << dest.toLocal8Bit() << "\n"; - stream << "Exec=" << dest.toLocal8Bit() << argstring.toLocal8Bit() << "\n"; - stream << "Name=" << name.toLocal8Bit() << "\n"; - stream << "Icon=" << icon.toLocal8Bit() << "\n"; - - stream.flush(); - f.close(); - - f.setPermissions(f.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeGroup | QFileDevice::ExeOther); - - return true; + location = PathCombine(location, name + ".desktop"); + qDebug("location: %s", qPrintable(location)); + + QFile f(location); + f.open(QIODevice::WriteOnly | QIODevice::Text); + QTextStream stream(&f); + + QString argstring; + if (!args.empty()) + argstring = " '" + args.join("' '") + "'"; + + stream << "[Desktop Entry]" << "\n"; + stream << "Type=Application" << "\n"; + stream << "TryExec=" << dest.toLocal8Bit() << "\n"; + stream << "Exec=" << dest.toLocal8Bit() << argstring.toLocal8Bit() << "\n"; + stream << "Name=" << name.toLocal8Bit() << "\n"; + stream << "Icon=" << icon.toLocal8Bit() << "\n"; + + stream.flush(); + f.close(); + + f.setPermissions(f.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeGroup | QFileDevice::ExeOther); + + return true; #elif WINDOWS - QFile file(path, name + ".lnk"); - WCHAR *file_w; - WCHAR *dest_w; - WCHAR *args_w; - file.fileName().toWCharArray(file_w); - dest.toWCharArray(dest_w); - args.toWCharArray(args_w); - return SUCCEEDED(CreateLink(file_w, dest_w, args_w)); + // TODO: Fix +// QFile file(PathCombine(location, name + ".lnk")); +// WCHAR *file_w; +// WCHAR *dest_w; +// WCHAR *args_w; +// file.fileName().toWCharArray(file_w); +// dest.toWCharArray(dest_w); + +// QString argStr; +// for (int i = 0; i < args.count(); i++) +// { +// argStr.append(args[i]); +// argStr.append(" "); +// } +// argStr.toWCharArray(args_w); + +// return SUCCEEDED(CreateLink(file_w, dest_w, args_w)); + return false; #else - qWarning("Desktop Shortcuts not supported on your platform!"); - return false; + qWarning("Desktop Shortcuts not supported on your platform!"); + return false; #endif } |