Skip to content

Commit

Permalink
Fix path selection for files (images, music, ...)
Browse files Browse the repository at this point in the history
Dirty patch with chdir... but seems to work so far !
  • Loading branch information
Charles de Noyelle committed Feb 25, 2020
1 parent 5627fa8 commit 2bd5cc6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/Tga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

#include <iostream>
#include <fstream>
#include <string.h> // Fix Artifact ID: 2927098

#include <string> // Fix Artifact ID: 2927098
// removed ".h" for 0.6.6 : maybe will create bugs ?
// => removing makes GRAPHDIR work again !
#include "Tga.h"
#include "OSGraphics.h"
#include "StringUtil.h"
Expand All @@ -28,7 +29,7 @@ Tga* Tga::Load(const string &resource_name) {

// FIXME this!
full_name = string(GRAPHDIR) + "/" + full_name;

//cout <<full_name<< "\n";
ifstream file(full_name.c_str(), ios::in|ios::binary|ios::ate);
if (!file.is_open())
throw LinthesiaError("Couldn't open TGA resource (" + full_name + ").");
Expand Down
2 changes: 1 addition & 1 deletion src/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
#include <string>

// See CHANGELOG for a list of what has changed between versions
static const std::string LinthesiaVersionString = "0.5";
static const std::string LinthesiaVersionString = "0.6.6";

#endif // __LINTHESIA_VERSION_H__
32 changes: 26 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@
#include <pwd.h>
#include <sys/stat.h>

#include <iostream>
#include <libgen.h>

#ifndef GRAPHDIR
#define GRAPHDIR "../graphics"
#define GRAPHDIR "../graphics"
#endif

using namespace std;
Expand All @@ -50,8 +53,7 @@ const static string friendly_app_name = STRING("Linthesia " <<
const static string error_header1 = "Linthesia detected a";
const static string error_header2 = " problem and must close:\n\n";
const static string error_footer = "\n\nIf you don't think this should have "
"happened, please\ncontact Oscar (on Linthesia sourceforge site) and\n"
"describe what you were doing when the problem\noccurred. Thanks.";
"happened, please fill a bug report on : \nhttps://github.com/linthesia/linthesia\n\nThank you.";

const static int vsync_interval = 1;

Expand Down Expand Up @@ -361,6 +363,14 @@ bool cmdOptionExists(char** begin, char** end, const std::string & option)
return std::find(begin, end, option) != end;
}

std::string getExePath()
// https://stackoverflow.com/questions/23943239/how-to-get-path-to-current-exe-file-on-linux
{
char result[ PATH_MAX ];
ssize_t count = readlink( "/proc/self/exe", result, PATH_MAX );
return std::string( dirname(result), (count > 0) ? count : 0 );
}

int main(int argc, char *argv[]) {
Gtk::Main main_loop(argc, argv);
Gtk::GL::init(argc, argv);
Expand All @@ -386,7 +396,7 @@ int main(int argc, char *argv[]) {
if (file_opt.length() > 0 &&
file_opt[file_opt.length()-1] == '\"')
file_opt = file_opt.substr(0, file_opt.length() - 1);

Midi *midi = 0;

// attempt to open the midi file given on the command line first
Expand Down Expand Up @@ -429,7 +439,7 @@ int main(int argc, char *argv[]) {
return 1;
}
}

/* Loading the Sqlite Library
*/
string tmp_user_db_str = UserSetting::Get("sqlite_db", "");
Expand Down Expand Up @@ -472,7 +482,17 @@ int main(int argc, char *argv[]) {
window.show_all();

window.set_title(friendly_app_name);
window.set_icon_from_file(string(GRAPHDIR) + "/app_icon.ico");

struct stat st;
chdir (getExePath().c_str());

if ( !stat((GRAPHDIR + std::string("/linthesia.png")).c_str(),&st) == 0) {
fprintf(stderr, "FATAL : File not found : make install not done ?\n");
cout << (GRAPHDIR + std::string("/linthesia.png")) << "\n";
// exit(0);
}

window.set_icon_from_file(GRAPHDIR + std::string("/linthesia.png"));

if (fullscreen) {
window.fullscreen();
Expand Down

0 comments on commit 2bd5cc6

Please sign in to comment.