MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / EnableAutoStart

Method EnableAutoStart

AutoStart/AutoStart-Windows.cpp:59–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57}
58
59bool AutoStart::EnableAutoStart(AutoStartInfo autostart_info)
60{
61 bool success = false;
62
63 /*-------------------------------------------------*\
64 | Check if the filename is valid |
65 \*-------------------------------------------------*/
66 if(autostart_file != "")
67 {
68 bool weInitialised = false;
69 HRESULT result;
70 IShellLinkW* shellLink = NULL;
71
72 std::wstring exepathw = utf8_decode(autostart_info.path);
73 std::wstring argumentsw = utf8_decode(autostart_info.args);
74 std::wstring startupfilepathw = utf8_decode(autostart_file);
75 std::wstring descriptionw = utf8_decode(autostart_info.desc);
76 std::wstring iconw = utf8_decode(autostart_info.path);
77
78 result = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_ALL, IID_IShellLinkW, (void**)&shellLink);
79
80 /*---------------------------------------------*\
81 | If not initialized, initialize |
82 \*---------------------------------------------*/
83 if(result == CO_E_NOTINITIALIZED)
84 {
85 weInitialised = true;
86 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
87 result = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_ALL, IID_IShellLinkW, (void**)&shellLink);
88 }
89
90 /*---------------------------------------------*\
91 | If successfully initialized, save a shortcut |
92 | from the AutoStart parameters |
93 \*---------------------------------------------*/
94 if(SUCCEEDED(result))
95 {
96 shellLink->SetPath(exepathw.c_str());
97 shellLink->SetArguments(argumentsw.c_str());
98 shellLink->SetDescription(descriptionw.c_str());
99 shellLink->SetIconLocation(iconw.c_str(), 0);
100
101 IPersistFile* persistFile;
102
103 result = shellLink->QueryInterface(IID_IPersistFile, (void**)&persistFile);
104
105 if(SUCCEEDED(result))
106 {
107 result = persistFile->Save(startupfilepathw.c_str(), TRUE);
108 success = SUCCEEDED(result);
109 persistFile->Release();
110 }
111
112 shellLink->Release();
113 }
114
115 /*---------------------------------------------*\
116 | Uninitialize when done |

Callers

nothing calls this directly

Calls 2

utf8_decodeFunction · 0.85
SaveMethod · 0.45

Tested by

no test coverage detected