6
6
#include "common/parsing.h"
7
7
#include "common/properties.h"
8
8
#include "common/processing.h"
9
+ #include "util/binary.h"
10
+ #include "util/path.h"
9
11
#include "detection/displayserver/displayserver.h"
10
- #include "util/stringUtils.h"
11
12
12
13
#include <ctype.h>
13
14
#ifdef __FreeBSD__
@@ -195,6 +196,45 @@ static void getUnity(FFstrbuf* result, FF_MAYBE_UNUSED FFDEOptions* options)
195
196
ffStrbufSubstrBeforeFirstC (result , '"' );
196
197
}
197
198
199
+ static bool extractTdeVersion (const char * line , uint32_t len , void * userdata )
200
+ {
201
+ int count = 0 ;
202
+ sscanf (line , "R%*d.%*d.%*d%n" , & count );
203
+ if (count == 0 ) return true;
204
+
205
+ ffStrbufSetNS ((FFstrbuf * ) userdata , len , line );
206
+ return false;
207
+ }
208
+
209
+ static const char * getTrinity (FFstrbuf * result , FFDEOptions * options )
210
+ {
211
+ FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate ();
212
+ const char * error = ffFindExecutableInPath ("tde-config" , & path );
213
+ if (error ) return "Failed to find tde-config path" ;
214
+
215
+ ffStrbufSubstrBeforeLastC (& path , '/' );
216
+ ffStrbufAppendS (& path , "/../lib/libtdecore.so" );
217
+
218
+ if (ffBinaryExtractStrings (path .chars , extractTdeVersion , result , strlen ("R0.0.0" )) == NULL )
219
+ return NULL ;
220
+
221
+ if (options -> slowVersionDetection )
222
+ {
223
+ ffStrbufClear (& path );
224
+ ffProcessAppendStdOut (& path , (char * const []){
225
+ "tde-config" ,
226
+ "--version" ,
227
+ NULL
228
+ });
229
+
230
+ ffParsePropLines (path .chars , "TDE: " , result );
231
+ return NULL ;
232
+ }
233
+
234
+ return "All methods failed" ;
235
+ }
236
+
237
+
198
238
const char * ffDetectDEVersion (const FFstrbuf * deName , FFstrbuf * result , FFDEOptions * options )
199
239
{
200
240
if (!instance .config .general .detectVersion ) return "Disabled by config" ;
@@ -215,6 +255,8 @@ const char* ffDetectDEVersion(const FFstrbuf* deName, FFstrbuf* result, FFDEOpti
215
255
getBudgie (result , options );
216
256
else if (ffStrbufEqualS (deName , FF_DE_PRETTY_UNITY ))
217
257
getUnity (result , options );
258
+ else if (ffStrbufEqualS (deName , "trinity" ))
259
+ getTrinity (result , options );
218
260
else
219
261
return "Unsupported DE" ;
220
262
return NULL ;
0 commit comments