From 75aa0fbf70018c293b890ddb0b021da204be9010 Mon Sep 17 00:00:00 2001 From: sirius-m Date: Fri, 2 Oct 2009 10:14:05 +0000 Subject: [PATCH] startup shortcut works --- bugs.txt | 1 - changelog.txt | 2 +- ui.cpp | 75 ++++++++++++++++++++++++++++++++++++--------------- ui.h | 1 + 4 files changed, 55 insertions(+), 24 deletions(-) diff --git a/bugs.txt b/bugs.txt index 348c359e8a..0f00111e94 100644 --- a/bugs.txt +++ b/bugs.txt @@ -1,4 +1,3 @@ Known bugs: -- For some reason, CreateHardLink doesn't add a shortcut to the startup folder - When the program is minimized to tray, double clicking the icon only restores it to the task bar - Window flickers when blocks are added (problem with repainting?) \ No newline at end of file diff --git a/changelog.txt b/changelog.txt index 685eb6292b..fee4f66183 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,5 +2,5 @@ Changes after 0.1.5: -------------------- + Options dialog layout changed - added the UI options panel + Minimize to tray feature -+ Startup on system boot feature ++ Startup on system boot feature (adds a shortcut to the Startup folder) + Ask before closing \ No newline at end of file diff --git a/ui.cpp b/ui.cpp index 751a50be68..e69630d398 100644 --- a/ui.cpp +++ b/ui.cpp @@ -859,18 +859,6 @@ void CMainFrame::OnMenuFileExit(wxCommandEvent& event) Close(true); } -void GenerateBitcoins(bool flag) -{ - fGenerateBitcoins = flag; - nTransactionsUpdated++; - CWalletDB().WriteSetting("fGenerateBitcoins", fGenerateBitcoins); - if (fGenerateBitcoins) - if (_beginthread(ThreadBitcoinMiner, 0, NULL) == -1) - printf("Error: _beginthread(ThreadBitcoinMiner) failed\n"); - - taskBarIcon->UpdateTooltip(); -} - void CMainFrame::OnMenuOptionsGenerate(wxCommandEvent& event) { GenerateBitcoins(event.IsChecked()); @@ -3394,24 +3382,67 @@ void ApplyUISettings() { taskBarIcon->Hide(); // Autostart on system startup? - if (startOnSysBoot) { - // Get the startup folder path - char targetPath[ MAX_PATH ]; - SHGetSpecialFolderPath(0, targetPath, CSIDL_STARTUP, 0); - strcat(targetPath, "\\bitcoin.lnk"); + // Get the startup folder shortcut path + char linkPath[ MAX_PATH ]; + SHGetSpecialFolderPath(0, linkPath, CSIDL_STARTUP, 0); + strcat(linkPath, "\\Bitcoin.lnk"); - // And the current executable path - char currentPath[ MAX_PATH ]; - GetModuleFileName(NULL, currentPath, _MAX_PATH + 1); + // If the shortcut exists already, remove it for updating + remove(linkPath); - // Create the shortcut - CreateHardLink(targetPath, currentPath, NULL); + if (startOnSysBoot) { + CoInitialize(NULL); + // Get the current executable path + char exePath[ MAX_PATH ]; + GetModuleFileName(NULL, exePath, _MAX_PATH + 1); + + HRESULT hres = NULL; + IShellLink* psl = NULL; + // Get a pointer to the IShellLink interface. + hres = CoCreateInstance(CLSID_ShellLink, NULL, + CLSCTX_INPROC_SERVER, IID_IShellLink, + reinterpret_cast(&psl)); + + if (SUCCEEDED(hres)) + { + IPersistFile* ppf = NULL; + // Set the path to the shortcut target + psl->SetPath(exePath); + // Query IShellLink for the IPersistFile interface for + // saving the shortcut in persistent storage. + hres = psl->QueryInterface(IID_IPersistFile, + reinterpret_cast(&ppf)); + if (SUCCEEDED(hres)) + { + WCHAR wsz[MAX_PATH]; + // Ensure that the string is ANSI. + MultiByteToWideChar(CP_ACP, 0, linkPath, -1, + wsz, MAX_PATH); + // Save the link by calling IPersistFile::Save. + hres = ppf->Save(wsz, TRUE); + ppf->Release(); + } + psl->Release(); + } + CoUninitialize(); } } +void GenerateBitcoins(bool flag) +{ + fGenerateBitcoins = flag; + nTransactionsUpdated++; + CWalletDB().WriteSetting("fGenerateBitcoins", fGenerateBitcoins); + if (fGenerateBitcoins) + if (_beginthread(ThreadBitcoinMiner, 0, NULL) == -1) + printf("Error: _beginthread(ThreadBitcoinMiner) failed\n"); + + taskBarIcon->UpdateTooltip(); +} + // randsendtest to bitcoin address diff --git a/ui.h b/ui.h index 5f3897c1be..11c88147ac 100644 --- a/ui.h +++ b/ui.h @@ -28,6 +28,7 @@ extern void CrossThreadCall(int nID, void* pdata); extern void MainFrameRepaint(); extern void Shutdown(void* parg); void ApplyUISettings(); +void GenerateBitcoins(bool flag); // UI settings extern int minimizeToTray;