startup shortcut works
authorsirius-m <sirius-m@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Fri, 2 Oct 2009 10:14:05 +0000 (10:14 +0000)
committersirius-m <sirius-m@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Fri, 2 Oct 2009 10:14:05 +0000 (10:14 +0000)
bugs.txt
changelog.txt
ui.cpp
ui.h

index 348c359..0f00111 100644 (file)
--- a/bugs.txt
+++ b/bugs.txt
@@ -1,4 +1,3 @@
 Known bugs:\r
-- For some reason, CreateHardLink doesn't add a shortcut to the startup folder\r
 - When the program is minimized to tray, double clicking the icon only restores it to the task bar\r
 - Window flickers when blocks are added (problem with repainting?)
\ No newline at end of file
index 685eb62..fee4f66 100644 (file)
@@ -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 751a50b..e69630d 100644 (file)
--- a/ui.cpp
+++ b/ui.cpp
@@ -859,18 +859,6 @@ void CMainFrame::OnMenuFileExit(wxCommandEvent& event)
     Close(true);\r
 }\r
 \r
-void GenerateBitcoins(bool flag)\r
-{\r
-       fGenerateBitcoins = flag;\r
-    nTransactionsUpdated++;\r
-    CWalletDB().WriteSetting("fGenerateBitcoins", fGenerateBitcoins);\r
-    if (fGenerateBitcoins)\r
-        if (_beginthread(ThreadBitcoinMiner, 0, NULL) == -1)\r
-            printf("Error: _beginthread(ThreadBitcoinMiner) failed\n");\r
-\r
-    taskBarIcon->UpdateTooltip();\r
-}\r
-\r
 void CMainFrame::OnMenuOptionsGenerate(wxCommandEvent& event)\r
 {\r
     GenerateBitcoins(event.IsChecked());\r
@@ -3394,24 +3382,67 @@ void ApplyUISettings() {
                taskBarIcon->Hide();\r
 \r
        // Autostart on system startup?\r
-       if (startOnSysBoot) {\r
-               // Get the startup folder path\r
-               char targetPath[ MAX_PATH ];\r
-               SHGetSpecialFolderPath(0, targetPath, CSIDL_STARTUP, 0);\r
-               strcat(targetPath, "\\bitcoin.lnk");\r
+       // Get the startup folder shortcut path\r
+       char linkPath[ MAX_PATH ];\r
+       SHGetSpecialFolderPath(0, linkPath, CSIDL_STARTUP, 0);\r
+       strcat(linkPath, "\\Bitcoin.lnk");\r
 \r
-               // And the current executable path\r
-               char currentPath[ MAX_PATH ];\r
-               GetModuleFileName(NULL, currentPath, _MAX_PATH + 1);\r
+       // If the shortcut exists already, remove it for updating\r
+       remove(linkPath);\r
 \r
-               // Create the shortcut\r
-               CreateHardLink(targetPath, currentPath, NULL);\r
+       if (startOnSysBoot) {\r
+               CoInitialize(NULL);\r
+               // Get the current executable path\r
+               char exePath[ MAX_PATH ];\r
+               GetModuleFileName(NULL, exePath, _MAX_PATH + 1);\r
+\r
+               HRESULT hres = NULL;\r
+               IShellLink* psl = NULL;\r
+               // Get a pointer to the IShellLink interface.\r
+               hres = CoCreateInstance(CLSID_ShellLink, NULL,\r
+                               CLSCTX_INPROC_SERVER, IID_IShellLink,\r
+                               reinterpret_cast<void**>(&psl));\r
+\r
+               if (SUCCEEDED(hres))\r
+               {\r
+                       IPersistFile* ppf = NULL;\r
+                       // Set the path to the shortcut target\r
+                       psl->SetPath(exePath);\r
+                       // Query IShellLink for the IPersistFile interface for\r
+                       // saving the shortcut in persistent storage.\r
+                       hres = psl->QueryInterface(IID_IPersistFile,\r
+                                       reinterpret_cast<void**>(&ppf));\r
+                       if (SUCCEEDED(hres))\r
+                       {\r
+                               WCHAR wsz[MAX_PATH];\r
+                               // Ensure that the string is ANSI.\r
+                               MultiByteToWideChar(CP_ACP, 0, linkPath, -1,\r
+                                               wsz, MAX_PATH);\r
+                               // Save the link by calling IPersistFile::Save.\r
+                               hres = ppf->Save(wsz, TRUE);\r
+                               ppf->Release();\r
+                       }\r
+                       psl->Release();\r
+               }\r
+               CoUninitialize();\r
        }\r
 }\r
 \r
 \r
 \r
 \r
+void GenerateBitcoins(bool flag)\r
+{\r
+       fGenerateBitcoins = flag;\r
+    nTransactionsUpdated++;\r
+    CWalletDB().WriteSetting("fGenerateBitcoins", fGenerateBitcoins);\r
+    if (fGenerateBitcoins)\r
+        if (_beginthread(ThreadBitcoinMiner, 0, NULL) == -1)\r
+            printf("Error: _beginthread(ThreadBitcoinMiner) failed\n");\r
+\r
+    taskBarIcon->UpdateTooltip();\r
+}\r
+\r
 \r
 \r
 // randsendtest to bitcoin address\r
diff --git a/ui.h b/ui.h
index 5f3897c..11c8814 100644 (file)
--- a/ui.h
+++ b/ui.h
@@ -28,6 +28,7 @@ extern void CrossThreadCall(int nID, void* pdata);
 extern void MainFrameRepaint();\r
 extern void Shutdown(void* parg);\r
 void ApplyUISettings();\r
+void GenerateBitcoins(bool flag);\r
 \r
 // UI settings\r
 extern int minimizeToTray;\r