Permalink
Browse files

Merged changes necessary for windows functionality back into master and

added proper sauerbraten home directory searching.
  • Loading branch information...
1 parent 41311f2 commit b0707bb402755d0f8b5c29510d99c9cbae00032a @MorganBorman committed May 15, 2012
View
BIN src/Icons/200px-Gnome-accessories-text-editor.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN src/Icons/200px-Gnome-dialog-information.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN src/Icons/200px-Gnome-edit-delete.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
12 src/Makefile
@@ -1,8 +1,18 @@
-authmanager: main.cpp filebuffer.o cube2crypto.o
+authmanager: main.o filebuffer.o cube2crypto.o
g++ -Wall -g -o $@ $^ `pkg-config --cflags --libs --static gtk+-2.0` -export-dynamic
+main.o: main.cpp filebuffer.h auth_model.cpp event_handlers.cpp
+ g++ -c -Wall -g -o $@ $< `pkg-config --cflags --libs --static gtk+-2.0` -export-dynamic
+
filebuffer.o: filebuffer.cpp filebuffer.h
g++ -c -Wall -g -o $@ $<
cube2crypto.o: cube2crypto.cpp shared/crypto.cpp shared/tools.h
g++ -c -Wall -g -o $@ $<
+
+w32dist: authmanager
+ cp authmanager w32dist/
+ cp -r Icons w32dist/
+
+clean:
+ rm -rf *.o authmanager
View
79 src/auth_model.cpp
@@ -30,36 +30,85 @@ void read_config_buffer(AuthManager *authManager, FileBuffer *fb)
}
}
-void load_auth_information(AuthManager *authManager)
+bool load_auth_information(AuthManager *authManager)
{
- char autoexec_filename[512];
- char authcfg_filename[512];
+ const char **rel_prefix;
- #if defined __GNUC__
- const char *homeDir = getenv("HOME");
- #elif defined _WIN32
- const char homeDir[MAX_PATH];
- const DWORD ret = GetEnvironmentVariableA("USERPROFILE",buff,MAX_PATH);
+ int sauer_home_length;
+ char *sauer_home;
+
+ char *autoexec_filename;
+ char *authcfg_filename;
+
+ #if defined _WIN32 || defined _WIN64
+ char homeDir[MAX_PATH];
+ char progDir[MAX_PATH];
+ int ret = GetEnvironmentVariableA("USERPROFILE", homeDir, MAX_PATH);
if (ret==0 || ret>MAX_PATH)
- homeDir = 0;
+ return false;
+ ret = SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, 0, progDir);
+ if (ret==0 || ret>MAX_PATH)
+ return false;
+ #else
+ const char *homeDir = getenv("HOME");
+ const char *progDir = "";
#endif
- if(!homeDir) return;
-
- printf("Sauerbraten home dir = "SAUERBRATEN_HOME_PATH"\n", homeDir);
+ if(!homeDir || !progDir) return false;
- snprintf(autoexec_filename, 512, SAUERBRATEN_HOME_PATH"autoexec.cfg", homeDir);
- snprintf(authcfg_filename, 512, SAUERBRATEN_HOME_PATH"auth.cfg", homeDir);
+ for(unsigned int lx = 0; lx < NUMLOCATIONS; lx++) {
+ //home_locations[lx].relative_to
+ //home_locations[lx].path
+
+ if(home_locations[lx].relative_to == PROGDIR)
+ rel_prefix = &progDir;
+ else if(home_locations[lx].relative_to == HOMEDIR)
+ rel_prefix = &homeDir;
+ else
+ return false;
+
+ sauer_home_length = strlen(*rel_prefix) + strlen(FS_DELIM) + strlen(home_locations[lx].path) + 1;
+
+
+
+ sauer_home = (char *)malloc(sizeof(char)*(sauer_home_length));
- readfb(&authManager->auth_cfg_buffer, authcfg_filename);
+ snprintf(sauer_home, sauer_home_length, "%s%s%s", *rel_prefix, FS_DELIM, home_locations[lx].path);
+
+ printf("Checking for Sauerbraten home dir = '%s'\n", sauer_home);
+
+ if(directory_exists(sauer_home)) break;
+
+ free(sauer_home);
+ sauer_home = NULL;
+ }
+
+ if(!sauer_home) return false;
+
+ printf("Sauerbraten home dir = %s\n", sauer_home);
+
+ int autoexec_filename_length = sauer_home_length + strlen(FS_DELIM) + strlen("autoexec.cfg") + 1;
+ int authcfg_filename_length = sauer_home_length + strlen(FS_DELIM) + strlen("auth.cfg") + 1;
+
+ autoexec_filename = (char *)malloc(sizeof(char)*(autoexec_filename_length));
+ authcfg_filename = (char *)malloc(sizeof(char)*(authcfg_filename_length));
+
+ snprintf(autoexec_filename, autoexec_filename_length, "%s%sautoexec.cfg", sauer_home, FS_DELIM);
+ snprintf(authcfg_filename, authcfg_filename_length, "%s%sauth.cfg", sauer_home, FS_DELIM);
+
+ readfb(&authManager->auth_cfg_buffer, authcfg_filename);
readfb(&authManager->autoexec_cfg_buffer, autoexec_filename);
+ free(autoexec_filename);
+ free(authcfg_filename);
+
printf("finished reading files.\n");
read_config_buffer(authManager, &authManager->auth_cfg_buffer);
read_config_buffer(authManager, &authManager->autoexec_cfg_buffer);
printf("finished reading auth keys.\n");
+ return true;
}
void write_row(AuthManager *authManager, GtkTreeIter *iter)
View
62 src/authmanager.glade
@@ -25,14 +25,14 @@
</columns>
</object>
<object class="GtkAction" id="action_close">
- <property name="label" translatable="yes">Close</property>
- <property name="short_label" translatable="yes">Close</property>
- <property name="tooltip" translatable="yes">Close the authManager</property>
+ <property name="label">Close</property>
+ <property name="short_label">Close</property>
+ <property name="tooltip">Close the authManager</property>
<property name="stock_id">gtk-close</property>
</object>
<object class="GtkAction" id="action_new">
- <property name="label" translatable="yes">New</property>
- <property name="tooltip" translatable="yes">Add a new auth key</property>
+ <property name="label">New</property>
+ <property name="tooltip">Add a new auth key</property>
<property name="stock_id">gtk-add</property>
</object>
<object class="GtkWindow" id="editdialog_window">
@@ -199,6 +199,47 @@
</object>
</child>
</object>
+ <object class="GtkMessageDialog" id="errordialog_nodir">
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Fatal error</property>
+ <property name="resizable">False</property>
+ <property name="modal">True</property>
+ <property name="type_hint">dialog</property>
+ <property name="skip_taskbar_hint">True</property>
+ <property name="message_type">error</property>
+ <property name="buttons">close</property>
+ <property name="text" translatable="yes">authManager could not locate the sauerbraten configuration directory. Will now exit.</property>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="dialog-vbox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkHButtonBox" id="dialog-action_area">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ </child>
+ </object>
<object class="GtkWindow" id="infodialog_window">
<property name="can_focus">False</property>
<property name="border_width">20</property>
@@ -430,6 +471,7 @@
<property name="label" translatable="yes">Close</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="gtk_main_quit" swapped="no"/>
+ <signal name="clicked" handler="gtk_false" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@@ -451,7 +493,7 @@
<signal name="button-press-event" handler="on_KeyView_button_press_event" swapped="no"/>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn_enabled">
- <property name="title" translatable="yes">Enabled</property>
+ <property name="title">Enabled</property>
<child>
<object class="GtkCellRendererToggle" id="cellrenderertoggle_enabled"/>
<attributes>
@@ -463,7 +505,7 @@
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn_authname">
<property name="resizable">True</property>
- <property name="title" translatable="yes">Auth Name</property>
+ <property name="title">Auth Name</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
@@ -475,7 +517,7 @@
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn_privkey">
<property name="resizable">True</property>
- <property name="title" translatable="yes">Private Key</property>
+ <property name="title">Private Key</property>
<property name="expand">True</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
@@ -488,7 +530,7 @@
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn_domain">
<property name="resizable">True</property>
- <property name="title" translatable="yes">Domain</property>
+ <property name="title">Domain</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext3"/>
<attributes>
@@ -499,7 +541,7 @@
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn_actions">
- <property name="title" translatable="yes">Actions</property>
+ <property name="title">Actions</property>
<child>
<object class="GtkCellRendererPixbuf" id="cellrendererpixbuf_info"/>
<attributes>
View
2 src/cube2crypto.cpp
@@ -16,7 +16,7 @@ extern "C"
{
char *cube2crypto_hashstring(const char *str, int hashlen)
{
- char *hash = (char*)malloc(sizeof(char[hashlen+1]));
+ char *hash = (char*)malloc(sizeof(char)*(hashlen+1));
if(!crypto::hashstring(str, hash, hashlen)) *hash = '\0';
return hash;
}
View
22 src/event_handlers.cpp
@@ -1,23 +1,23 @@
extern "C"
{
- void on_newdialog_entry_changed(GtkObject *object, AuthManager *authManager)
+ G_MODULE_EXPORT void on_newdialog_entry_changed(GtkObject *object, AuthManager *authManager)
{
}
- void on_editdialog_entry_changed(GtkObject *object, AuthManager *authManager)
+ G_MODULE_EXPORT void on_editdialog_entry_changed(GtkObject *object, AuthManager *authManager)
{
}
- void on_infodialog_button_ok_clicked(GtkObject *object, AuthManager *authManager)
+ G_MODULE_EXPORT void on_infodialog_button_ok_clicked(GtkObject *object, AuthManager *authManager)
{
gtk_widget_hide(authManager->infodialog.window);
}
- void on_editdialog_button_update_clicked(GtkObject *object, AuthManager *authManager)
+ G_MODULE_EXPORT void on_editdialog_button_update_clicked(GtkObject *object, AuthManager *authManager)
{
gtk_widget_hide(authManager->editdialog.window);
@@ -35,33 +35,33 @@ extern "C"
write_row(authManager, &iter);
}
- void on_editdialog_button_cancel_clicked(GtkObject *object, AuthManager *authManager)
+ G_MODULE_EXPORT void on_editdialog_button_cancel_clicked(GtkObject *object, AuthManager *authManager)
{
gtk_widget_hide(authManager->editdialog.window);
}
- void on_toolbutton_new_clicked(GtkObject *object, AuthManager *authManager)
+ G_MODULE_EXPORT void on_toolbutton_new_clicked(GtkObject *object, AuthManager *authManager)
{
gtk_entry_set_text(authManager->newdialog.entry_authname, "");
gtk_entry_set_text(authManager->newdialog.entry_privkey, "");
gtk_entry_set_text(authManager->newdialog.entry_domain, "");
gtk_widget_show(authManager->newdialog.window);
}
- void on_newdialog_button_add_clicked(GtkObject *object, AuthManager *authManager)
+ G_MODULE_EXPORT void on_newdialog_button_add_clicked(GtkObject *object, AuthManager *authManager)
{
gtk_widget_hide(authManager->newdialog.window);
create_row(authManager, gtk_entry_get_text(authManager->newdialog.entry_authname),
gtk_entry_get_text(authManager->newdialog.entry_privkey),
gtk_entry_get_text(authManager->newdialog.entry_domain));
}
- void on_newdialog_button_cancel_clicked(GtkObject *object, AuthManager *authManager)
+ G_MODULE_EXPORT void on_newdialog_button_cancel_clicked(GtkObject *object, AuthManager *authManager)
{
gtk_widget_hide(authManager->newdialog.window);
}
- void on_newdialog_clipboard_received(GtkClipboard *clipboard, const char *text_data, AuthManager *authManager)
+ G_MODULE_EXPORT void on_newdialog_clipboard_received(GtkClipboard *clipboard, const char *text_data, AuthManager *authManager)
{
char authname[512];
char privkey[51];
@@ -86,13 +86,13 @@ extern "C"
}
}
- void on_newdialog_button_fromclip_clicked(GtkObject *object, AuthManager *authManager)
+ G_MODULE_EXPORT void on_newdialog_button_fromclip_clicked(GtkObject *object, AuthManager *authManager)
{
GtkClipboard *clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
gtk_clipboard_request_text(clipboard, (GtkClipboardTextReceivedFunc)on_newdialog_clipboard_received, authManager);
}
- bool on_KeyView_button_press_event(GtkObject *object, GdkEventButton *event, AuthManager *authManager)
+ G_MODULE_EXPORT bool on_KeyView_button_press_event(GtkObject *object, GdkEventButton *event, AuthManager *authManager)
{
GtkCellRenderer *renderer = NULL;
GtkTreeIter iter;
View
99 src/main.cpp
@@ -2,30 +2,66 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include "filebuffer.h"
#include "cube2crypto.h"
-#ifdef _WIN32
- // windows (32-bit)
- #define SAUERBRATEN_HOME_PATH "%s\\My Games\\Sauerbraten\\"
-#elif _WIN64
- // windows (64-bit)
- #define SAUERBRATEN_HOME_PATH "%s\\My Games\Sauerbraten\\"
+#if defined _WIN32 || defined _WIN64
+ #define FS_DELIM "\\"
+ #include <Windows.h>
+ #include <shlobj.h>
+#else
+ #define FS_DELIM "/"
+#endif
+
+enum{PROGDIR, HOMEDIR};
+
+typedef struct {
+ int relative_to;
+ char *path;
+} HomeLocation;
+
+#if defined _WIN32 || defined _WIN64
+
+/* Array of sauerbraten home directories and what they're relative to. */
+static HomeLocation home_locations[] = {
+ {HOMEDIR, "My Games\Sauerbraten"},
+ {PROGDIR, "Sauerbraten\\"}
+};
+
#elif __APPLE__
- // osx
- #define SAUERBRATEN_HOME_PATH "%s/Library/Application Support/sauerbraten/"
-#elif __linux
- // linux
- #define SAUERBRATEN_HOME_PATH "%s/.sauerbraten/"
-#elif __unix // all unices not caught above
- // unix
- #define SAUERBRATEN_HOME_PATH "%s/.sauerbraten/"
-#elif __posix
- // posix
- #define SAUERBRATEN_HOME_PATH "%s/.sauerbraten/"
+
+static HomeLocation home_locations[] = {
+ {HOMEDIR, "Library/Application Support/sauerbraten"}
+};
+
+#else
+
+static HomeLocation home_locations[] = {
+ {HOMEDIR, ".sauerbraten"}
+};
+
#endif
+#define NUMLOCATIONS sizeof(home_locations)/sizeof(HomeLocation)
+
+bool directory_exists(const char *path)
+{
+ struct stat stat_data;
+ if(stat(path, &stat_data)) return false;
+
+ if (stat_data.st_mode & S_IFDIR)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
enum
{
COL_ENABLED = 0, /* gboolean */
@@ -71,6 +107,8 @@ typedef struct {
typedef struct
{
GtkWidget *window;
+ GtkWidget *errordialog_nodir;
+
GtkListStore *key_store;
GtkTreeView *key_view;
@@ -97,9 +135,9 @@ GdkPixbuf *get_stock_icon(GtkIconTheme *icon_theme, const char *icon_name, int s
GError *error = NULL;
GdkPixbuf *return_pixbuf = NULL;
- return_pixbuf = gtk_icon_theme_load_icon(icon_theme, icon_name, size /*px*/, (GtkIconLookupFlags)0, &error);
+ return_pixbuf = gdk_pixbuf_new_from_file_at_size(icon_name, size /*px*/, size /*px*/, &error);
if(!return_pixbuf) {
- g_print("Couldn't load icon: %s", error->message);
+ g_print("Couldn't load icon: %s\n", error->message);
g_free(error);
return NULL;
}
@@ -147,6 +185,8 @@ int main (int argc, char *argv[])
authManager->key_store = GTK_LIST_STORE(gtk_builder_get_object(builder, "KeyStore"));
authManager->key_view = GTK_TREE_VIEW(gtk_builder_get_object(builder, "KeyView"));
+ authManager->errordialog_nodir = GTK_WIDGET(gtk_builder_get_object(builder, "errordialog_nodir"));
+
authManager->enabled_renderer = GTK_CELL_RENDERER(gtk_builder_get_object(builder, "cellrenderertoggle_enabled"));
authManager->info_renderer = GTK_CELL_RENDERER(gtk_builder_get_object(builder, "cellrendererpixbuf_info"));
authManager->edit_renderer = GTK_CELL_RENDERER(gtk_builder_get_object(builder, "cellrendererpixbuf_edit"));
@@ -180,9 +220,9 @@ int main (int argc, char *argv[])
GtkIconTheme *icon_theme = gtk_icon_theme_get_default();
- authManager->info_icon_pixbuf = get_stock_icon(icon_theme, "gtk-dialog-info");
- authManager->edit_icon_pixbuf = get_stock_icon(icon_theme, "gtk-edit");
- authManager->delete_icon_pixbuf = get_stock_icon(icon_theme, "gtk-delete");
+ authManager->info_icon_pixbuf = get_stock_icon(icon_theme, "Icons"FS_DELIM"200px-Gnome-dialog-information.png");
+ authManager->edit_icon_pixbuf = get_stock_icon(icon_theme, "Icons"FS_DELIM"200px-Gnome-accessories-text-editor.png");
+ authManager->delete_icon_pixbuf = get_stock_icon(icon_theme, "Icons"FS_DELIM"200px-Gnome-edit-delete.png");
if(!authManager->info_icon_pixbuf || !authManager->edit_icon_pixbuf || !authManager->delete_icon_pixbuf)
{
@@ -193,13 +233,22 @@ int main (int argc, char *argv[])
return(1);
}
- load_auth_information(authManager);
-
- gtk_main();
+ if(!load_auth_information(authManager))
+ {
+ gtk_dialog_run(GTK_DIALOG(authManager->errordialog_nodir));
+ }
+ else
+ {
+ gtk_main();
+ }
freefb(&authManager->auth_cfg_buffer);
freefb(&authManager->autoexec_cfg_buffer);
+ if(authManager->info_icon_pixbuf) g_object_unref(authManager->info_icon_pixbuf);
+ if(authManager->edit_icon_pixbuf) g_object_unref(authManager->edit_icon_pixbuf);
+ if(authManager->delete_icon_pixbuf) g_object_unref(authManager->delete_icon_pixbuf);
+
g_slice_free(AuthManager, authManager);
return 0;
}
View
BIN src/w32dist/Icons/200px-Gnome-accessories-text-editor.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN src/w32dist/Icons/200px-Gnome-dialog-information.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN src/w32dist/Icons/200px-Gnome-edit-delete.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN src/w32dist/freetype6.dll
Binary file not shown.
View
BIN src/w32dist/intl.dll
Binary file not shown.
View
BIN src/w32dist/libatk-1.0-0.dll
Binary file not shown.
View
BIN src/w32dist/libcairo-2.dll
Binary file not shown.
View
BIN src/w32dist/libexpat-1.dll
Binary file not shown.
View
BIN src/w32dist/libfontconfig-1.dll
Binary file not shown.
View
BIN src/w32dist/libgcc_s_dw2-1.dll
Binary file not shown.
View
BIN src/w32dist/libgdk-win32-2.0-0.dll
Binary file not shown.
View
BIN src/w32dist/libgdk_pixbuf-2.0-0.dll
Binary file not shown.
View
BIN src/w32dist/libgio-2.0-0.dll
Binary file not shown.
View
BIN src/w32dist/libglib-2.0-0.dll
Binary file not shown.
View
BIN src/w32dist/libgmodule-2.0-0.dll
Binary file not shown.
View
BIN src/w32dist/libgobject-2.0-0.dll
Binary file not shown.
View
BIN src/w32dist/libgthread-2.0-0.dll
Binary file not shown.
View
BIN src/w32dist/libgtk-win32-2.0-0.dll
Binary file not shown.
View
BIN src/w32dist/libpangocairo-1.0-0.dll
Binary file not shown.
View
BIN src/w32dist/libpangoft2-1.0-0.dll
Binary file not shown.
View
BIN src/w32dist/libpangowin32-1.0-0.dll
Binary file not shown.
View
BIN src/w32dist/libpng14-14.dll
Binary file not shown.
View
BIN src/w32dist/libstdc++-6.dll
Binary file not shown.

0 comments on commit b0707bb

Please sign in to comment.