diff --git a/Sconstruct b/Sconstruct index 610d27c2..e922b0be 100644 --- a/Sconstruct +++ b/Sconstruct @@ -3,7 +3,7 @@ import sys MAJOR = 5 MINOR = 5 -BUG = 1 +BUG = 2 EXTRA = "" DEBUG = False diff --git a/include/libsaria/path.h b/include/libsaria/path.h index bb6af798..d8ff5a5a 100644 --- a/include/libsaria/path.h +++ b/include/libsaria/path.h @@ -17,6 +17,7 @@ struct file string get_saria_dir(); void make_saria_dir(); +bool exists(string); sid_t lookup_songid(string &); #endif /* LIBSARIA_PATH_H */ diff --git a/include/libsaria/path.h.orig b/include/libsaria/path.h.orig new file mode 100644 index 00000000..bb6af798 --- /dev/null +++ b/include/libsaria/path.h.orig @@ -0,0 +1,22 @@ +#ifndef LIBSARIA_PATH_H +#define LIBSARIA_PATH_H + +#include + +#include +#include +using namespace std; + +#include + +struct file +{ + string name; + sid_t d_sid; +}; + +string get_saria_dir(); +void make_saria_dir(); +sid_t lookup_songid(string &); + +#endif /* LIBSARIA_PATH_H */ diff --git a/libsaria/audio/controls.cpp b/libsaria/audio/controls.cpp index ef47ef07..7dce9416 100644 --- a/libsaria/audio/controls.cpp +++ b/libsaria/audio/controls.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "audio.h" static string cur_file; @@ -30,7 +31,7 @@ static void reset() void load_file(GstElement *playbin, string file) { - if (file == "") + if (file == "" || !exists(file)) return; string uri = "file://" + file; println("Loading uri: " + uri); diff --git a/libsaria/path/dir.cpp b/libsaria/path/dir.cpp index 29fc28ae..ef6ff6ac 100644 --- a/libsaria/path/dir.cpp +++ b/libsaria/path/dir.cpp @@ -40,6 +40,12 @@ void make_saria_dir() mkdir(saria.c_str(), mode); } +bool exists(string path) +{ + struct stat stat; + return lstat(path.c_str(), &stat) == 0; +} + sid_t lookup_songid(string &filepath) { struct stat stat; diff --git a/libsaria/path/dir.cpp.orig b/libsaria/path/dir.cpp.orig new file mode 100644 index 00000000..29fc28ae --- /dev/null +++ b/libsaria/path/dir.cpp.orig @@ -0,0 +1,50 @@ + +#include +#include +#include +#include + +#include +using namespace std; + +/* I want to use the d_type field in a dirent */ +#ifndef __USE_BSD +#define __USE_BSD +#endif + +#ifdef DEBUG + static string SARIA_DIR = "/saria-debug"; +#else /* DEBUG */ + static string SARIA_DIR = "/saria"; +#endif /* DEBUG */ + +string get_saria_dir() +{ + string saria = getenv("HOME"); + string xdg = getenv("XDG_CONFIG_HOME"); + + if (xdg == "") + saria += "/.config"; + else if (xdg.compare(0, saria.size(), saria) == 0) + saria = xdg + "/"; + else + saria += "/" + xdg += "/"; + + return saria += SARIA_DIR; +} + +void make_saria_dir() +{ + string saria = get_saria_dir(); + mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; + mkdir(saria.c_str(), mode); +} + +sid_t lookup_songid(string &filepath) +{ + struct stat stat; + int err = lstat(filepath.c_str(), &stat); + if (err != 0) + return err; + return stat.st_ino; +}