Missed adding patch for guitarmaster earlier, here it is.

This commit is contained in:
Scott McCreary
2013-11-26 01:55:14 +00:00
parent c3cebc89f6
commit 88a2844bd2

View File

@@ -0,0 +1,212 @@
From 4929c586441b40f7046487bc9b9a7dd887e3e605 Mon Sep 17 00:00:00 2001
From: Luke <noryb009@gmail.com>
Date: Sun, 24 Nov 2013 07:51:48 +0000
Subject: [PATCH] Search for songs directory
---
TApp.cpp | 5 +++--
TApp.h | 4 +++-
TMainWindow.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
TMainWindow.h | 4 +++-
main.cpp | 11 +++++++++-
5 files changed, 79 insertions(+), 8 deletions(-)
diff --git a/TApp.cpp b/TApp.cpp
index b38dbe1..a9d89ec 100644
--- a/TApp.cpp
+++ b/TApp.cpp
@@ -10,10 +10,11 @@ using namespace org::toxic;
using namespace std;
-TApp::TApp():BApplication("application/x-vnd.guitar-master")
+TApp::TApp(BString * UserSpecifiedSongDir):BApplication("application/x-vnd.guitar-master")
{
cout<<"Guitar Master project"<<endl;
cout<<"Toxic Labs 2008/2009"<<endl;
+ this->UserSpecifiedSongDir = UserSpecifiedSongDir;
}
@@ -27,5 +28,5 @@ void TApp::ReadyToRun()
{
cout<<"ready!!"<<endl;
- window = new TMainWindow(BRect(50,50,300,300));
+ window = new TMainWindow(BRect(50,50,300,300), UserSpecifiedSongDir);
}
diff --git a/TApp.h b/TApp.h
index f9a6a93..ecf8f00 100644
--- a/TApp.h
+++ b/TApp.h
@@ -5,6 +5,7 @@
#ifndef _TApp_
#define _TApp_
+#include <String.h>
#include <Application.h>
#include "TMainWindow.h"
@@ -16,9 +17,10 @@ namespace org
{
private:
TMainWindow * window;
+ BString * UserSpecifiedSongDir;
public:
- TApp();
+ TApp(BString * UserSpecifiedSongDir = NULL);
~TApp();
virtual void ReadyToRun();
diff --git a/TMainWindow.cpp b/TMainWindow.cpp
index d84cbd4..f16be1d 100644
--- a/TMainWindow.cpp
+++ b/TMainWindow.cpp
@@ -11,12 +11,17 @@
#include <String.h>
#include <iostream>
+#include <unistd.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include <stdlib.h>
+
using namespace org::toxic;
using namespace org::toxic::resources;
using namespace std;
-TMainWindow::TMainWindow(BRect frame): BWindow(frame,"Guitar Master",B_TITLED_WINDOW,B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
+TMainWindow::TMainWindow(BRect frame, BString * UserSpecifiedSongDir): BWindow(frame,"Guitar Master",B_TITLED_WINDOW,B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
{
cout<<"Main window"<<endl;
@@ -46,9 +51,61 @@ TMainWindow::TMainWindow(BRect frame): BWindow(frame,"Guitar Master",B_TITLED_WI
//Songs menu
menu = new BMenu("Songs");
// fill with available song list...
+
+ BString homeDir = getenv("HOME");
+ if(homeDir == NULL) {
+ struct passwd *pw = getpwuid(getuid());
+ homeDir = pw->pw_dir;
+ }
+
+ BString * songLocations[13];
+ songLocations[0] = UserSpecifiedSongDir;
+ songLocations[1] = new BString("songs");
+ songLocations[2] = new BString("/music/GuitarMaster");
+ songLocations[2]->Prepend(homeDir);
+ songLocations[3] = new BString("/music/guitarmaster");
+ songLocations[3]->Prepend(homeDir);
+ songLocations[4] = new BString("/music/Guitar Master");
+ songLocations[4]->Prepend(homeDir);
+ songLocations[5] = new BString("/music/guitar master");
+ songLocations[5]->Prepend(homeDir);
+ songLocations[6] = new BString("/Music/GuitarMaster");
+ songLocations[6]->Prepend(homeDir);
+ songLocations[7] = new BString("/Music/guitarmaster");
+ songLocations[7]->Prepend(homeDir);
+ songLocations[8] = new BString("/Music/Guitar Master");
+ songLocations[8]->Prepend(homeDir);
+ songLocations[9] = new BString("/Music/guitar master");
+ songLocations[9]->Prepend(homeDir);
+ songLocations[10] = new BString("/music");
+ songLocations[10]->Prepend(homeDir);
+ songLocations[11] = new BString("/Music");
+ songLocations[11]->Prepend(homeDir);
+ songLocations[12] = new BString(homeDir);
+
+ cout<<"Searching for songs directory..."<<endl;
+
+ BDirectory * songs_dir_check;
+ for(int i=0; i<sizeof(songLocations)/sizeof(BString *); i++) {
+ if(songLocations[i] != NULL) {
+ cout<<" Checking "<<songLocations[i]->String()<<endl;
+ songs_dir_check = new BDirectory(songLocations[i]->String());
+ if(songs_dir_check->InitCheck() == B_OK) {
+ SongsDirLocation = new BString(*songLocations[i]);
+ delete songs_dir_check;
+ break;
+ }
+ delete songs_dir_check;
+ }
+ }
+
+ for(int i=0; i<sizeof(songLocations)/sizeof(BString *); i++) {
+ delete songLocations[i];
+ }
+
cout<<"Reading songs directory..."<<endl;
- BDirectory songs_dir("songs");
+ BDirectory songs_dir(SongsDirLocation->String());
BEntry entry;
char str[B_FILE_NAME_LENGTH];
BMessage * message;
@@ -128,7 +185,7 @@ void TMainWindow::MessageReceived(BMessage * mesg)
case T_MSG_SELECT_SONG:
mesg->FindString("song",&str);
- spath<<"songs/"<<str<<"/notes.mid";
+ spath<<SongsDirLocation->String()<<"/"<<str<<"/notes.mid";
cout<<"Selected: "<<spath.String()<<endl;
diff --git a/TMainWindow.h b/TMainWindow.h
index b5a3ea4..db632ec 100644
--- a/TMainWindow.h
+++ b/TMainWindow.h
@@ -5,6 +5,7 @@
#include <Window.h>
#include <MessageRunner.h>
+#include <String.h>
#include "TGameView.h"
#define T_MSG_FRAME 0x00FF0011
@@ -20,10 +21,11 @@ namespace org
TGameView * gameview;
BMessageRunner * timer;
+ BString * SongsDirLocation;
public:
- TMainWindow(BRect frame);
+ TMainWindow(BRect frame, BString * songDirectory = NULL);
~TMainWindow();
diff --git a/main.cpp b/main.cpp
index 6e9a650..da8d16b 100644
--- a/main.cpp
+++ b/main.cpp
@@ -3,13 +3,22 @@
* Toxic Labs
*/
+#include <String.h>
#include "TApp.h"
using namespace org::toxic;
int main (int argc,char * argv[])
{
- TApp app;
+ BString * UserSpecifiedSongDir;
+ UserSpecifiedSongDir = NULL;
+ // see if song directory was specified
+ if(argc > 1)
+ {
+ UserSpecifiedSongDir = new BString(argv[1]);
+ }
+
+ TApp app(UserSpecifiedSongDir);
app.Run();
--
1.8.3.4