Clean up comment formatting in AutoStart files
This commit is contained in:
parent
3cbc4e5570
commit
64686c92cd
4 changed files with 157 additions and 158 deletions
|
|
@ -26,21 +26,21 @@ bool AutoStart::DisableAutoStart()
|
||||||
std::error_code autostart_file_remove_errcode;
|
std::error_code autostart_file_remove_errcode;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Check if the filename is valid |
|
| Check if the filename is valid |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(autostart_file != "")
|
if(autostart_file != "")
|
||||||
{
|
{
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| If file doesn't exist, disable is successful |
|
| If file doesn't exist, disable is successful |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
if(!filesystem::exists(autostart_file))
|
if(!filesystem::exists(autostart_file))
|
||||||
{
|
{
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| Otherwise, delete the file |
|
| Otherwise, delete the file |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
success = filesystem::remove(autostart_file, autostart_file_remove_errcode);
|
success = filesystem::remove(autostart_file, autostart_file_remove_errcode);
|
||||||
|
|
@ -63,27 +63,26 @@ bool AutoStart::EnableAutoStart(AutoStartInfo autostart_info)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Check if the filename is valid |
|
| Check if the filename is valid |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(autostart_file != "")
|
if(autostart_file != "")
|
||||||
{
|
{
|
||||||
std::ofstream autostart_file_stream(autostart_file, std::ios::out | std::ios::trunc);
|
std::ofstream autostart_file_stream(autostart_file, std::ios::out | std::ios::trunc);
|
||||||
|
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| Error out if the file could not be opened |
|
| Error out if the file could not be opened |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
if(!autostart_file_stream)
|
if(!autostart_file_stream)
|
||||||
{
|
{
|
||||||
LOG_ERROR("[AutoStart] Could not open %s for writing.", autostart_file.c_str());
|
LOG_ERROR("[AutoStart] Could not open %s for writing.", autostart_file.c_str());
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| Otherwise, write the file |
|
| Otherwise, write the file |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//autostart_file_stream << desktop_file;
|
|
||||||
autostart_file_stream.close();
|
autostart_file_stream.close();
|
||||||
success = !autostart_file_stream.fail();
|
success = !autostart_file_stream.fail();
|
||||||
|
|
||||||
|
|
@ -103,9 +102,9 @@ bool AutoStart::EnableAutoStart(AutoStartInfo autostart_info)
|
||||||
|
|
||||||
bool AutoStart::IsAutoStartEnabled()
|
bool AutoStart::IsAutoStartEnabled()
|
||||||
{
|
{
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Check if the filename is valid |
|
| Check if the filename is valid |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(autostart_file != "")
|
if(autostart_file != "")
|
||||||
{
|
{
|
||||||
return(filesystem::exists(autostart_file));
|
return(filesystem::exists(autostart_file));
|
||||||
|
|
@ -118,9 +117,9 @@ bool AutoStart::IsAutoStartEnabled()
|
||||||
|
|
||||||
std::string AutoStart::GetExePath()
|
std::string AutoStart::GetExePath()
|
||||||
{
|
{
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Create the OpenRGB executable path |
|
| Create the OpenRGB executable path |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
char exepath[ PATH_MAX ];
|
char exepath[ PATH_MAX ];
|
||||||
|
|
||||||
ssize_t count = readlink("/proc/self/exe", exepath, PATH_MAX);
|
ssize_t count = readlink("/proc/self/exe", exepath, PATH_MAX);
|
||||||
|
|
@ -134,16 +133,16 @@ void AutoStart::InitAutoStart(std::string name)
|
||||||
|
|
||||||
autostart_name = name;
|
autostart_name = name;
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Get home and config paths |
|
| Get home and config paths |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
const char *xdg_config_home = getenv("XDG_CONFIG_HOME");
|
const char *xdg_config_home = getenv("XDG_CONFIG_HOME");
|
||||||
const char *home = getenv("HOME");
|
const char *home = getenv("HOME");
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Determine where the autostart .desktop files are |
|
| Determine where the autostart .desktop files are |
|
||||||
| kept |
|
| kept |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(xdg_config_home != NULL)
|
if(xdg_config_home != NULL)
|
||||||
{
|
{
|
||||||
autostart_dir = xdg_config_home;
|
autostart_dir = xdg_config_home;
|
||||||
|
|
@ -155,9 +154,9 @@ void AutoStart::InitAutoStart(std::string name)
|
||||||
autostart_dir = autostart_dir + "/.config/autostart/";
|
autostart_dir = autostart_dir + "/.config/autostart/";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Check if the filename is valid |
|
| Check if the filename is valid |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(autostart_dir != "")
|
if(autostart_dir != "")
|
||||||
{
|
{
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
|
|
|
||||||
|
|
@ -26,21 +26,21 @@ bool AutoStart::DisableAutoStart()
|
||||||
std::error_code autostart_file_remove_errcode;
|
std::error_code autostart_file_remove_errcode;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Check if the filename is valid |
|
| Check if the filename is valid |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(autostart_file != "")
|
if(autostart_file != "")
|
||||||
{
|
{
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| If file doesn't exist, disable is successful |
|
| If file doesn't exist, disable is successful |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
if(!filesystem::exists(autostart_file))
|
if(!filesystem::exists(autostart_file))
|
||||||
{
|
{
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| Otherwise, delete the file |
|
| Otherwise, delete the file |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
success = filesystem::remove(autostart_file, autostart_file_remove_errcode);
|
success = filesystem::remove(autostart_file, autostart_file_remove_errcode);
|
||||||
|
|
@ -63,25 +63,25 @@ bool AutoStart::EnableAutoStart(AutoStartInfo autostart_info)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Check if the filename is valid |
|
| Check if the filename is valid |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(autostart_file != "")
|
if(autostart_file != "")
|
||||||
{
|
{
|
||||||
std::string desktop_file = GenerateDesktopFile(autostart_info);
|
std::string desktop_file = GenerateDesktopFile(autostart_info);
|
||||||
std::ofstream autostart_file_stream(autostart_file, std::ios::out | std::ios::trunc);
|
std::ofstream autostart_file_stream(autostart_file, std::ios::out | std::ios::trunc);
|
||||||
|
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| Error out if the file could not be opened |
|
| Error out if the file could not be opened |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
if(!autostart_file_stream)
|
if(!autostart_file_stream)
|
||||||
{
|
{
|
||||||
LOG_ERROR("[AutoStart] Could not open %s for writing.", autostart_file.c_str());
|
LOG_ERROR("[AutoStart] Could not open %s for writing.", autostart_file.c_str());
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| Otherwise, write the file |
|
| Otherwise, write the file |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
autostart_file_stream << desktop_file;
|
autostart_file_stream << desktop_file;
|
||||||
|
|
@ -104,9 +104,9 @@ bool AutoStart::EnableAutoStart(AutoStartInfo autostart_info)
|
||||||
|
|
||||||
bool AutoStart::IsAutoStartEnabled()
|
bool AutoStart::IsAutoStartEnabled()
|
||||||
{
|
{
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Check if the filename is valid |
|
| Check if the filename is valid |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(autostart_file != "")
|
if(autostart_file != "")
|
||||||
{
|
{
|
||||||
return(filesystem::exists(autostart_file));
|
return(filesystem::exists(autostart_file));
|
||||||
|
|
@ -119,9 +119,9 @@ bool AutoStart::IsAutoStartEnabled()
|
||||||
|
|
||||||
std::string AutoStart::GetExePath()
|
std::string AutoStart::GetExePath()
|
||||||
{
|
{
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Create the OpenRGB executable path |
|
| Create the OpenRGB executable path |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
char exepath[ PATH_MAX ];
|
char exepath[ PATH_MAX ];
|
||||||
|
|
||||||
ssize_t count = readlink("/proc/self/exe", exepath, PATH_MAX);
|
ssize_t count = readlink("/proc/self/exe", exepath, PATH_MAX);
|
||||||
|
|
@ -129,17 +129,17 @@ std::string AutoStart::GetExePath()
|
||||||
return(std::string(exepath, (count > 0) ? count : 0));
|
return(std::string(exepath, (count > 0) ? count : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------*\
|
/*---------------------------------------------------------*\
|
||||||
| Linux AutoStart Implementation |
|
| Linux AutoStart Implementation |
|
||||||
| Private Methods |
|
| Private Methods |
|
||||||
\*-----------------------------------------------------*/
|
\*---------------------------------------------------------*/
|
||||||
|
|
||||||
std::string AutoStart::GenerateDesktopFile(AutoStartInfo autostart_info)
|
std::string AutoStart::GenerateDesktopFile(AutoStartInfo autostart_info)
|
||||||
{
|
{
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Generate a .desktop file from the AutoStart |
|
| Generate a .desktop file from the AutoStart |
|
||||||
| parameters |
|
| parameters |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
std::stringstream fileContents;
|
std::stringstream fileContents;
|
||||||
|
|
||||||
fileContents << "[Desktop Entry]" << std::endl;
|
fileContents << "[Desktop Entry]" << std::endl;
|
||||||
|
|
@ -151,9 +151,9 @@ std::string AutoStart::GenerateDesktopFile(AutoStartInfo autostart_info)
|
||||||
fileContents << "Terminal=false" << std::endl;
|
fileContents << "Terminal=false" << std::endl;
|
||||||
fileContents << "Type=Application" << std::endl;
|
fileContents << "Type=Application" << std::endl;
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Add the executable path and arguments |
|
| Add the executable path and arguments |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
fileContents << "Exec=" << autostart_info.path;
|
fileContents << "Exec=" << autostart_info.path;
|
||||||
|
|
||||||
if (autostart_info.args != "")
|
if (autostart_info.args != "")
|
||||||
|
|
@ -172,16 +172,16 @@ void AutoStart::InitAutoStart(std::string name)
|
||||||
|
|
||||||
autostart_name = name;
|
autostart_name = name;
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Get home and config paths |
|
| Get home and config paths |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
const char *xdg_config_home = getenv("XDG_CONFIG_HOME");
|
const char *xdg_config_home = getenv("XDG_CONFIG_HOME");
|
||||||
const char *home = getenv("HOME");
|
const char *home = getenv("HOME");
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Determine where the autostart .desktop files are |
|
| Determine where the autostart .desktop files are |
|
||||||
| kept |
|
| kept |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(xdg_config_home != NULL)
|
if(xdg_config_home != NULL)
|
||||||
{
|
{
|
||||||
autostart_dir = xdg_config_home;
|
autostart_dir = xdg_config_home;
|
||||||
|
|
@ -193,9 +193,9 @@ void AutoStart::InitAutoStart(std::string name)
|
||||||
autostart_dir = autostart_dir + "/.config/autostart/";
|
autostart_dir = autostart_dir + "/.config/autostart/";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Check if the filename is valid |
|
| Check if the filename is valid |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(autostart_dir != "")
|
if(autostart_dir != "")
|
||||||
{
|
{
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
|
|
|
||||||
|
|
@ -26,21 +26,21 @@ bool AutoStart::DisableAutoStart()
|
||||||
std::error_code autostart_file_remove_errcode;
|
std::error_code autostart_file_remove_errcode;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Check if the filename is valid |
|
| Check if the filename is valid |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(autostart_file != "")
|
if(autostart_file != "")
|
||||||
{
|
{
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| If file doesn't exist, disable is successful |
|
| If file doesn't exist, disable is successful |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
if(!filesystem::exists(autostart_file))
|
if(!filesystem::exists(autostart_file))
|
||||||
{
|
{
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| Otherwise, delete the file |
|
| Otherwise, delete the file |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
success = filesystem::remove(autostart_file, autostart_file_remove_errcode);
|
success = filesystem::remove(autostart_file, autostart_file_remove_errcode);
|
||||||
|
|
@ -63,25 +63,25 @@ bool AutoStart::EnableAutoStart(AutoStartInfo autostart_info)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Check if the filename is valid |
|
| Check if the filename is valid |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(autostart_file != "")
|
if(autostart_file != "")
|
||||||
{
|
{
|
||||||
std::string desktop_file = GenerateLaunchAgentFile(autostart_info);
|
std::string desktop_file = GenerateLaunchAgentFile(autostart_info);
|
||||||
std::ofstream autostart_file_stream(autostart_file, std::ios::out | std::ios::trunc);
|
std::ofstream autostart_file_stream(autostart_file, std::ios::out | std::ios::trunc);
|
||||||
|
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| Error out if the file could not be opened |
|
| Error out if the file could not be opened |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
if(!autostart_file_stream)
|
if(!autostart_file_stream)
|
||||||
{
|
{
|
||||||
LOG_ERROR("[AutoStart] Could not open %s for writing.", autostart_file.c_str());
|
LOG_ERROR("[AutoStart] Could not open %s for writing.", autostart_file.c_str());
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| Otherwise, write the file |
|
| Otherwise, write the file |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
autostart_file_stream << desktop_file;
|
autostart_file_stream << desktop_file;
|
||||||
|
|
@ -104,9 +104,9 @@ bool AutoStart::EnableAutoStart(AutoStartInfo autostart_info)
|
||||||
|
|
||||||
bool AutoStart::IsAutoStartEnabled()
|
bool AutoStart::IsAutoStartEnabled()
|
||||||
{
|
{
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Check if the filename is valid |
|
| Check if the filename is valid |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(autostart_file != "")
|
if(autostart_file != "")
|
||||||
{
|
{
|
||||||
return(filesystem::exists(autostart_file));
|
return(filesystem::exists(autostart_file));
|
||||||
|
|
@ -119,9 +119,9 @@ bool AutoStart::IsAutoStartEnabled()
|
||||||
|
|
||||||
std::string AutoStart::GetExePath()
|
std::string AutoStart::GetExePath()
|
||||||
{
|
{
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Create the OpenRGB executable path |
|
| Create the OpenRGB executable path |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
char exepath[ PATH_MAX ];
|
char exepath[ PATH_MAX ];
|
||||||
uint32_t exesize = PATH_MAX;
|
uint32_t exesize = PATH_MAX;
|
||||||
|
|
||||||
|
|
@ -132,17 +132,17 @@ std::string AutoStart::GetExePath()
|
||||||
return("");
|
return("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------*\
|
/*---------------------------------------------------------*\
|
||||||
| MacOS AutoStart Implementation |
|
| MacOS AutoStart Implementation |
|
||||||
| Private Methods |
|
| Private Methods |
|
||||||
\*-----------------------------------------------------*/
|
\*---------------------------------------------------------*/
|
||||||
|
|
||||||
std::string AutoStart::GenerateLaunchAgentFile(AutoStartInfo autostart_info)
|
std::string AutoStart::GenerateLaunchAgentFile(AutoStartInfo autostart_info)
|
||||||
{
|
{
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Generate a .plist file from the AutoStart |
|
| Generate a .plist file from the AutoStart |
|
||||||
| parameters |
|
| parameters |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
std::stringstream fileContents;
|
std::stringstream fileContents;
|
||||||
|
|
||||||
fileContents << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
|
fileContents << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
|
||||||
|
|
@ -180,16 +180,16 @@ void AutoStart::InitAutoStart(std::string name)
|
||||||
|
|
||||||
autostart_name = name;
|
autostart_name = name;
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Determine where the autostart .desktop files are |
|
| Determine where the autostart .desktop files are |
|
||||||
| kept |
|
| kept |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
autostart_dir = getenv("HOME");
|
autostart_dir = getenv("HOME");
|
||||||
autostart_dir = autostart_dir + "/Library/LaunchAgents/";
|
autostart_dir = autostart_dir + "/Library/LaunchAgents/";
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Check if the filename is valid |
|
| Check if the filename is valid |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(autostart_dir != "")
|
if(autostart_dir != "")
|
||||||
{
|
{
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
|
|
|
||||||
|
|
@ -25,21 +25,21 @@ bool AutoStart::DisableAutoStart()
|
||||||
std::error_code autostart_file_remove_errcode;
|
std::error_code autostart_file_remove_errcode;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Check if the filename is valid |
|
| Check if the filename is valid |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(autostart_file != "")
|
if(autostart_file != "")
|
||||||
{
|
{
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| If file doesn't exist, disable is successful |
|
| If file doesn't exist, disable is successful |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
if(!filesystem::exists(autostart_file))
|
if(!filesystem::exists(autostart_file))
|
||||||
{
|
{
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| Otherwise, delete the file |
|
| Otherwise, delete the file |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
success = filesystem::remove(autostart_file, autostart_file_remove_errcode);
|
success = filesystem::remove(autostart_file, autostart_file_remove_errcode);
|
||||||
|
|
@ -62,9 +62,9 @@ bool AutoStart::EnableAutoStart(AutoStartInfo autostart_info)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Check if the filename is valid |
|
| Check if the filename is valid |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(autostart_file != "")
|
if(autostart_file != "")
|
||||||
{
|
{
|
||||||
bool weInitialised = false;
|
bool weInitialised = false;
|
||||||
|
|
@ -79,9 +79,9 @@ bool AutoStart::EnableAutoStart(AutoStartInfo autostart_info)
|
||||||
|
|
||||||
result = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_ALL, IID_IShellLinkW, (void**)&shellLink);
|
result = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_ALL, IID_IShellLinkW, (void**)&shellLink);
|
||||||
|
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| If not initialized, initialize |
|
| If not initialized, initialize |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
if(result == CO_E_NOTINITIALIZED)
|
if(result == CO_E_NOTINITIALIZED)
|
||||||
{
|
{
|
||||||
weInitialised = true;
|
weInitialised = true;
|
||||||
|
|
@ -89,10 +89,10 @@ bool AutoStart::EnableAutoStart(AutoStartInfo autostart_info)
|
||||||
result = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_ALL, IID_IShellLinkW, (void**)&shellLink);
|
result = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_ALL, IID_IShellLinkW, (void**)&shellLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| If successfully initialized, save a shortcut |
|
| If successfully initialized, save a shortcut |
|
||||||
| from the AutoStart parameters |
|
| from the AutoStart parameters |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
if(SUCCEEDED(result))
|
if(SUCCEEDED(result))
|
||||||
{
|
{
|
||||||
shellLink->SetPath(exepathw.c_str());
|
shellLink->SetPath(exepathw.c_str());
|
||||||
|
|
@ -114,9 +114,9 @@ bool AutoStart::EnableAutoStart(AutoStartInfo autostart_info)
|
||||||
shellLink->Release();
|
shellLink->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| Uninitialize when done |
|
| Uninitialize when done |
|
||||||
\*---------------------------------------------*/
|
\*-------------------------------------------------*/
|
||||||
if(weInitialised)
|
if(weInitialised)
|
||||||
{
|
{
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
|
|
@ -132,9 +132,9 @@ bool AutoStart::EnableAutoStart(AutoStartInfo autostart_info)
|
||||||
|
|
||||||
bool AutoStart::IsAutoStartEnabled()
|
bool AutoStart::IsAutoStartEnabled()
|
||||||
{
|
{
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Check if the filename is valid |
|
| Check if the filename is valid |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
if(autostart_file != "")
|
if(autostart_file != "")
|
||||||
{
|
{
|
||||||
return(filesystem::exists(autostart_file));
|
return(filesystem::exists(autostart_file));
|
||||||
|
|
@ -147,9 +147,9 @@ bool AutoStart::IsAutoStartEnabled()
|
||||||
|
|
||||||
std::string AutoStart::GetExePath()
|
std::string AutoStart::GetExePath()
|
||||||
{
|
{
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Create the OpenRGB executable path |
|
| Create the OpenRGB executable path |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
char exepath[MAX_PATH] = "";
|
char exepath[MAX_PATH] = "";
|
||||||
|
|
||||||
DWORD count = GetModuleFileNameA(NULL, exepath, MAX_PATH);
|
DWORD count = GetModuleFileNameA(NULL, exepath, MAX_PATH);
|
||||||
|
|
@ -157,10 +157,10 @@ std::string AutoStart::GetExePath()
|
||||||
return(std::string(exepath, (count > 0) ? count : 0));
|
return(std::string(exepath, (count > 0) ? count : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------*\
|
/*---------------------------------------------------------*\
|
||||||
| Windows AutoStart Implementation |
|
| Windows AutoStart Implementation |
|
||||||
| Private Methods |
|
| Private Methods |
|
||||||
\*-----------------------------------------------------*/
|
\*---------------------------------------------------------*/
|
||||||
|
|
||||||
void AutoStart::InitAutoStart(std::string name)
|
void AutoStart::InitAutoStart(std::string name)
|
||||||
{
|
{
|
||||||
|
|
@ -168,9 +168,9 @@ void AutoStart::InitAutoStart(std::string name)
|
||||||
|
|
||||||
autostart_name = name;
|
autostart_name = name;
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-----------------------------------------------------*\
|
||||||
| Get startup applications path |
|
| Get startup applications path |
|
||||||
\*-------------------------------------------------*/
|
\*-----------------------------------------------------*/
|
||||||
HRESULT result = SHGetFolderPathA(NULL, CSIDL_PROGRAMS, NULL, 0, startMenuPath);
|
HRESULT result = SHGetFolderPathA(NULL, CSIDL_PROGRAMS, NULL, 0, startMenuPath);
|
||||||
|
|
||||||
if(SUCCEEDED(result))
|
if(SUCCEEDED(result))
|
||||||
|
|
@ -185,10 +185,10 @@ void AutoStart::InitAutoStart(std::string name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------*\
|
/*---------------------------------------------------------*\
|
||||||
| Convert an UTF8 string to a wide Unicode String |
|
| Convert an UTF8 string to a wide Unicode String |
|
||||||
| (from wmi.cpp) |
|
| (from wmi.cpp) |
|
||||||
\*-----------------------------------------------------*/
|
\*---------------------------------------------------------*/
|
||||||
std::wstring AutoStart::utf8_decode(const std::string& str)
|
std::wstring AutoStart::utf8_decode(const std::string& str)
|
||||||
{
|
{
|
||||||
if(str.empty())
|
if(str.empty())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue