Skip to content

Commit

Permalink
Added option to create configuration shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
acidicoala committed Mar 30, 2021
1 parent b60990e commit d2c87b7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions IntegrationWizard/Resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ END
// CONFIG
//

IDR_DEFAULT_CONFIG CONFIG ".\\Config.jsonc"
IDR_DEFAULT_CONFIG CONFIG "..\\Config.jsonc"


/////////////////////////////////////////////////////////////////////////////
Expand All @@ -60,7 +60,7 @@ IDR_DEFAULT_CONFIG CONFIG ".\\Config.jsonc"

// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON "D:\\Dev\\VisualStudioProjects\\Koalageddon\\icon.ico"
IDI_ICON1 ICON "..\\icon.ico"

#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
Expand Down
55 changes: 50 additions & 5 deletions IntegrationWizard/src/winmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,43 @@ path getDesktopPath()
}



HRESULT createShortcut(wstring targetLocation, wstring shortcutLocation, wstring description)
{
HRESULT hres = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if(SUCCEEDED(hres))
{
IShellLink* psl = NULL;

// Get a pointer to the IShellLink interface. It is assumed that CoInitialize
// has already been called.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*) &psl);
if(SUCCEEDED(hres))
{
IPersistFile* ppf = NULL;

// Set the path to the shortcut target and add the description.
psl->SetPath(targetLocation.c_str());
psl->SetDescription(description.c_str());

// Query IShellLink for the IPersistFile interface, used for saving the
// shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*) &ppf);

if(SUCCEEDED(hres))
{
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(shortcutLocation.c_str(), TRUE);
ppf->Release();
}
psl->Release();
}
CoUninitialize();
}

return hres;
}

void firstSetup()
{
setReg(KOALAGEDDON_KEY, INSTALL_DIR, getCurrentProcessPath().parent_path().string());
Expand Down Expand Up @@ -86,15 +123,14 @@ void firstSetup()

configFile.write((char*) dataPtr, dataSize);
configFile.close();


}

void askForAction(
HINSTANCE hInstance,
map<int, IntegrationWizard::PlatformInstallation>& platforms,
Action* action,
int* platformID
int* platformID,
BOOL* createShortcut
)
{
TASKDIALOGCONFIG tdc = { sizeof(TASKDIALOGCONFIG) };
Expand Down Expand Up @@ -135,6 +171,7 @@ void askForAction(
tdc.pRadioButtons = radioButtons.data();
tdc.pszContent = szBodyText;
tdc.pszExpandedInformation = szExpandedInformation;
tdc.pszVerificationText = L"Create desktop shortcut to configuration file";
tdc.pszFooter = szFooter;
tdc.pszFooterIcon = TD_INFORMATION_ICON;
tdc.pfCallback = [](HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, LONG_PTR lpRefData)->HRESULT
Expand All @@ -147,7 +184,7 @@ void askForAction(
return S_OK;
};

if(SUCCEEDED(TaskDialogIndirect(&tdc, (int*) action, platformID, NULL)))
if(SUCCEEDED(TaskDialogIndirect(&tdc, (int*) action, platformID, createShortcut)))
{
logger->debug("Clicked button: {}", *action);

Expand Down Expand Up @@ -181,11 +218,12 @@ int APIENTRY wWinMain(

Action action;
int platformID;
BOOL shouldCreateShortcut = FALSE;

if(platforms.empty())
action = Action::NOTHING_TO_INSTALL;
else
askForAction(hInstance, platforms, &action, &platformID);
askForAction(hInstance, platforms, &action, &platformID, &shouldCreateShortcut);

switch(action)
{
Expand All @@ -196,8 +234,15 @@ int APIENTRY wWinMain(
logger->info("No action was taken. Terminating.");
break;
case Action::INSTALL_INTEGRATIONS:
[[fallthrough]];
case Action::REMOVE_INTEGRATIONS:
IntegrationWizard::alterPlatform(action, platformID, platforms);
if(shouldCreateShortcut)
createShortcut(
getConfigPath().wstring(),
(getDesktopPath() / "Config.lnk").wstring(),
L"Kolageddon Configuration File"
);
break;
case Action::NOTHING_TO_INSTALL:
MessageBox(NULL, L"Koalageddon did not find any installed platforms.", L"Nothing found", MB_ICONINFORMATION);
Expand Down
2 changes: 1 addition & 1 deletion Koalageddon.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
build_installer.bat = build_installer.bat
IntegrationWizard\Config.jsonc = IntegrationWizard\Config.jsonc
Config.jsonc = Config.jsonc
inno_setup.iss = inno_setup.iss
LICENSE.txt = LICENSE.txt
README.md = README.md
Expand Down

0 comments on commit d2c87b7

Please sign in to comment.