Skip to content

Commit 6ae5242

Browse files
vkarlsenCalcProgrammer1
authored andcommitted
Add FreeBSD support
1 parent 45755c7 commit 6ae5242

File tree

10 files changed

+337
-18
lines changed

10 files changed

+337
-18
lines changed

AutoStart/AutoStart-FreeBSD.cpp

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
#include "AutoStart-FreeBSD.h"
2+
#include "LogManager.h"
3+
#include "filesystem.h"
4+
5+
#include <fstream>
6+
#include <iostream>
7+
#include <unistd.h>
8+
#include <sstream>
9+
10+
/*-----------------------------------------------------*\
11+
| FreeBSD AutoStart Implementation |
12+
| Public Methods |
13+
\*-----------------------------------------------------*/
14+
15+
AutoStart::AutoStart(std::string name)
16+
{
17+
InitAutoStart(name);
18+
}
19+
20+
bool AutoStart::DisableAutoStart()
21+
{
22+
std::error_code autostart_file_remove_errcode;
23+
bool success = false;
24+
25+
/*-------------------------------------------------*\
26+
| Check if the filename is valid |
27+
\*-------------------------------------------------*/
28+
if(autostart_file != "")
29+
{
30+
/*---------------------------------------------*\
31+
| If file doesn't exist, disable is successful |
32+
\*---------------------------------------------*/
33+
if(!filesystem::exists(autostart_file))
34+
{
35+
success = true;
36+
}
37+
/*---------------------------------------------*\
38+
| Otherwise, delete the file |
39+
\*---------------------------------------------*/
40+
else
41+
{
42+
success = filesystem::remove(autostart_file, autostart_file_remove_errcode);
43+
44+
if(!success)
45+
{
46+
LOG_ERROR("[AutoStart] An error occurred removing the auto start file.");
47+
}
48+
}
49+
}
50+
else
51+
{
52+
LOG_ERROR("Could not establish correct autostart file path.");
53+
}
54+
55+
return(success);
56+
}
57+
58+
bool AutoStart::EnableAutoStart(AutoStartInfo autostart_info)
59+
{
60+
bool success = false;
61+
62+
/*-------------------------------------------------*\
63+
| Check if the filename is valid |
64+
\*-------------------------------------------------*/
65+
if(autostart_file != "")
66+
{
67+
std::ofstream autostart_file_stream(autostart_file, std::ios::out | std::ios::trunc);
68+
69+
/*---------------------------------------------*\
70+
| Error out if the file could not be opened |
71+
\*---------------------------------------------*/
72+
if(!autostart_file_stream)
73+
{
74+
LOG_ERROR("Could not open %s for writing.", autostart_file.c_str());
75+
success = false;
76+
}
77+
/*---------------------------------------------*\
78+
| Otherwise, write the file |
79+
\*---------------------------------------------*/
80+
else
81+
{
82+
//autostart_file_stream << desktop_file;
83+
autostart_file_stream.close();
84+
success = !autostart_file_stream.fail();
85+
86+
if (!success)
87+
{
88+
LOG_ERROR("An error occurred writing the auto start file.");
89+
}
90+
}
91+
}
92+
else
93+
{
94+
LOG_ERROR("Could not establish correct autostart file path.");
95+
}
96+
97+
return(success);
98+
}
99+
100+
bool AutoStart::IsAutoStartEnabled()
101+
{
102+
/*-------------------------------------------------*\
103+
| Check if the filename is valid |
104+
\*-------------------------------------------------*/
105+
if(autostart_file != "")
106+
{
107+
return(filesystem::exists(autostart_file));
108+
}
109+
else
110+
{
111+
return(false);
112+
}
113+
}
114+
115+
std::string AutoStart::GetExePath()
116+
{
117+
/*-------------------------------------------------*\
118+
| Create the OpenRGB executable path |
119+
\*-------------------------------------------------*/
120+
char exepath[ PATH_MAX ];
121+
122+
ssize_t count = readlink("/proc/self/exe", exepath, PATH_MAX);
123+
124+
return(std::string(exepath, (count > 0) ? count : 0));
125+
}
126+
127+
void AutoStart::InitAutoStart(std::string name)
128+
{
129+
std::string autostart_dir;
130+
131+
autostart_name = name;
132+
133+
/*-------------------------------------------------*\
134+
| Get home and config paths |
135+
\*-------------------------------------------------*/
136+
const char *xdg_config_home = getenv("XDG_CONFIG_HOME");
137+
const char *home = getenv("HOME");
138+
139+
/*-------------------------------------------------*\
140+
| Determine where the autostart .desktop files are |
141+
| kept |
142+
\*-------------------------------------------------*/
143+
if(xdg_config_home != NULL)
144+
{
145+
autostart_dir = xdg_config_home;
146+
autostart_dir = autostart_dir + "/autostart/";
147+
}
148+
else if(home != NULL)
149+
{
150+
autostart_dir = home;
151+
autostart_dir = autostart_dir + "/.config/autostart/";
152+
}
153+
154+
/*-------------------------------------------------*\
155+
| Check if the filename is valid |
156+
\*-------------------------------------------------*/
157+
if(autostart_dir != "")
158+
{
159+
std::error_code ec;
160+
161+
bool success = true;
162+
163+
if(!filesystem::exists(autostart_dir))
164+
{
165+
success = filesystem::create_directories(autostart_dir, ec);
166+
}
167+
168+
if(success)
169+
{
170+
autostart_file = autostart_dir + autostart_name + ".desktop";
171+
}
172+
}
173+
}
174+

AutoStart/AutoStart-FreeBSD.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include "AutoStart.h"
5+
6+
class AutoStart: public AutoStartInterface
7+
{
8+
public:
9+
AutoStart(std::string name);
10+
11+
bool DisableAutoStart();
12+
bool EnableAutoStart(AutoStartInfo autostart_info);
13+
bool IsAutoStartEnabled();
14+
std::string GetExePath();
15+
16+
private:
17+
void InitAutoStart(std::string name);
18+
std::string GenerateLaunchAgentFile(AutoStartInfo autostart_info);
19+
};

AutoStart/AutoStart.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ class AutoStartInterface
3737

3838
#ifdef __APPLE__
3939
#include "AutoStart-MacOS.h"
40-
#endif
40+
#endif
41+
42+
#ifdef __FreeBSD__
43+
#include "AutoStart-FreeBSD.h"
44+
#endif

Controllers/CorsairHydroController/CorsairHydroController.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
#include "RGBController.h"
88
#include <vector>
9+
#ifdef __FreeBSD__
10+
#include <libusb.h>
11+
#else
912
#include <libusb-1.0/libusb.h>
13+
#endif
1014

1115
#pragma once
1216

Controllers/CorsairHydroController/CorsairHydroControllerDetect.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
#include "RGBController.h"
44
#include "RGBController_CorsairHydro.h"
55
#include <vector>
6+
#ifdef __FreeBSD__
7+
#include <libusb.h>
8+
#else
69
#include <libusb-1.0/libusb.h>
10+
#endif
711

812
/*-----------------------------------------------------*\
913
| Corsair vendor ID |

Controllers/LianLiController/LianLiControllerDetect.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
#include "RGBController_LianLiUniHub.h"
1616
#include "ResourceManager.h"
1717

18+
#ifdef __FreeBSD__
19+
#include <libusb.h>
20+
#else
1821
#include <libusb-1.0/libusb.h>
22+
#endif
1923

2024
#define UNI_HUB_VID 0x0CF2
2125
#define UNI_HUB_PID 0x7750

Controllers/LianLiController/LianLiUniHubController.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515

1616
#include "RGBController.h"
1717

18+
#ifdef __FreeBSD__
19+
#include <libusb.h>
20+
#else
1821
#include <libusb-1.0/libusb.h>
22+
#endif
1923

2024
/*----------------------------------------------------------------------------*\
2125
| Global definitions. |

0 commit comments

Comments
 (0)