Dedupe, implement support for getting steam directory

Signed-off-by: Ikey Doherty <ikey@solus-project.com>
This commit is contained in:
Ikey Doherty
2017-10-22 00:10:49 +01:00
parent 1811ff5225
commit a691985541
4 changed files with 53 additions and 12 deletions
+41 -2
View File
@@ -15,11 +15,20 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "../common.h"
#include "files.h"
#include "nica/util.h"
const char *lsi_get_home_dir(void)
bool lsi_file_exists(const char *path)
{
__lsi_unused__ struct stat st = { 0 };
return lstat(path, &st) == 0;
}
const char *lsi_get_home_dir()
{
char *c = NULL;
struct passwd *p = NULL;
@@ -35,7 +44,7 @@ const char *lsi_get_home_dir(void)
return p->pw_dir;
}
char *lsi_get_user_config_dir(void)
char *lsi_get_user_config_dir()
{
const char *home = lsi_get_home_dir();
char *c = NULL;
@@ -45,6 +54,36 @@ char *lsi_get_user_config_dir(void)
return c;
}
/**
* Just use .local/share/Steam at this point..
*/
static inline char *lsi_get_fallback_steam_dir(const char *home)
{
char *p = NULL;
if (asprintf(&p, "%s/.local/share/Steam", home) < 0) {
return NULL;
}
return p;
}
char *lsi_get_steam_dir()
{
const char *homedir = NULL;
autofree(char) *candidate = NULL;
autofree(char) *resolv = NULL;
homedir = lsi_get_home_dir();
if (asprintf(&candidate, "%s/.steam/root", homedir) < 0) {
return NULL;
}
resolv = realpath(candidate, NULL);
if (!resolv || !lsi_file_exists(resolv)) {
return lsi_get_fallback_steam_dir(homedir);
}
return strdup(resolv);
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
+11
View File
@@ -13,6 +13,7 @@
#define _GNU_SOURCE
#include <stdbool.h>
#include <stdlib.h>
/**
@@ -25,6 +26,16 @@ const char *lsi_get_home_dir(void);
*/
char *lsi_get_user_config_dir(void);
/**
* Find out where Steam is installed
*/
char *lsi_get_steam_dir(void);
/**
* Quick helper to determine if the path exists
*/
bool lsi_file_exists(const char *path);
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
-10
View File
@@ -17,7 +17,6 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include "../common.h"
@@ -97,15 +96,6 @@ __lsi_inline__ static inline const char *lsi_preload_list(void)
*/
void lsi_report_failure(const char *s, ...);
/**
* Quick helper to determine if the path exists
*/
__lsi_inline__ static inline bool lsi_file_exists(const char *path)
{
__lsi_unused__ struct stat st = { 0 };
return lstat(path, &st) == 0;
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
+1
View File
@@ -17,6 +17,7 @@
#include <string.h>
#include <unistd.h>
#include "../common/files.h"
#include "config.h"
#include "lsi.h"