notsecure / uTox

Lightweight Tox client
utox.org
GNU General Public License v3.0
597 stars 149 forks source link

Add abillity to select a profile/save file through command line #1010

Closed SmoothDude closed 8 years ago

SmoothDude commented 9 years ago

Just launch utox --save mysave and it will load "mysave" or will create a new save under name "mysave". Also fixed bug, where saved theme in Window's version never loaded.

tsudoko commented 9 years ago

I'd suggest using -f/--file instead of --save, but it might be just what I'm used to.

LittleVulpix commented 9 years ago

Actually I'd suggest --profile instead of both of these as --file or --save might sound somewhat ambiguous

tsudoko commented 9 years ago

I think you're right, I was kind of confused about what this PR actually does.

LittleVulpix commented 9 years ago

I have one more question - how does this switch interact with the already-present --portable switch ( which does something similar to this PR ) ?

SmoothDude commented 9 years ago

With --portable uTox will create "tox" folder in the directory, where it was launched and save all settings, including uTox configuration and tox_save profile here. --profiles will make it easy to work with multiple profiles, without need to launch uTox from different places or renaming toxs directories.

GrayHatter commented 9 years ago

@SmoothDude

diff --git a/main.h b/main.h
index 7340b8b..c5c9385 100644
--- a/main.h
+++ b/main.h
@@ -20,29 +20,42 @@
 #include <tox/tox.h>
 #include <tox/toxav.h>
 #include <vpx/vpx_codec.h>
+#include <vpx/vpx_image.h>

 #ifdef EMOJI_IDS
 #include <base_emoji.h>
 #endif

 #define countof(x) (sizeof(x)/sizeof(*(x)))
+
+//  fixes compile with apple headers
+#ifndef __OBJC__
 #define volatile(x) (*((volatile typeof(x)*)&x))
+#endif

+// Defaults
 #define DEFAULT_NAME "Tox User"
 #define DEFAULT_STATUS "Toxing on uTox"
 #define DEFAULT_SCALE 2

+// Versions
 #define TITLE "uTox"
 #define SUB_TITLE "(Alpha)"
-#define VERSION "0.2.q"
+#define VERSION "0.3.0"

+// Limits and sizes
 #define MAX_CALLS 16
+#define MAX_NUM_FRIENDS 256
 #define MAX_BACKLOG_MESSAGES 128

+#define MAX_NUM_GROUPS 512
 #define TOX_FRIEND_ADDRESS_SIZE TOX_ADDRESS_SIZE

 #define UTOX_FILE_NAME_LENGTH 1024

+#define isdesktop(x) ((size_t)(x) == 1)
+
+// Structs
 typedef struct
 {
     uint8_t version, scale, enableipv6, disableudp;
@@ -55,7 +68,8 @@ typedef struct
     uint8_t audio_filtering_enabled : 1;
     uint8_t close_to_tray : 1;
     uint8_t start_in_tray : 1;
-    uint8_t zero : 2;
+    uint8_t auto_startup : 1;
+    uint8_t no_typing_notifications : 1;
     uint16_t audio_device_in;
     uint16_t audio_device_out;
     uint8_t theme;
@@ -79,6 +93,77 @@ typedef struct {

 typedef struct edit_change EDIT_CHANGE;

+// Enums
+enum
+{
+    CURSOR_NONE,
+    CURSOR_TEXT,
+    CURSOR_HAND,
+    CURSOR_SELECT,
+    CURSOR_ZOOM_IN,
+    CURSOR_ZOOM_OUT,
+};
+
+enum {
+    FONT_TEXT,
+    FONT_TITLE,
+
+    /*FONT_MSG,
+    FONT_MSG_NAME,
+    FONT_MSG_LINK,*/
+
+    FONT_SELF_NAME,
+    FONT_STATUS,
+    FONT_LIST_NAME,
+
+    FONT_MISC,
+};
+
+//sysmenu icons
+enum {
+    BM_ONLINE = 1,
+    BM_AWAY,
+    BM_BUSY,
+    BM_OFFLINE,
+    BM_STATUS_NOTIFY,
+
+    BM_ADD,
+    BM_GROUPS,
+    BM_TRANSFER,
+    BM_SETTINGS,
+
+    BM_LBUTTON,
+    BM_SBUTTON,
+
+    BM_CONTACT,
+    BM_GROUP,
+
+    BM_FILE,
+    BM_CALL,
+    BM_VIDEO,
+
+    BM_FT,
+    BM_FTM,
+    BM_FTB1,
+    BM_FTB2,
+
+    BM_NO,
+    BM_PAUSE,
+    BM_RESUME,
+    BM_YES,
+
+    BM_SCROLLHALFTOP,
+    BM_SCROLLHALFBOT,
+    BM_STATUSAREA,
+
+    BM_CB1,
+    BM_CB2,
+    BM_CHAT_SEND,
+    BM_CHAT_SEND_OVERLAY,
+    BM_CI1
+};
+
+// µTox includes
 #include "unused.h"

 #include "png/png.h"
@@ -86,14 +171,18 @@ typedef struct edit_change EDIT_CHANGE;
 #include "tox.h"

 #ifdef __WIN32__
-#include "win32/main.h"
+#include "windows/main.h"
 #else
 #ifdef __ANDROID__
 #include "android/main.h"
 #else
+#ifdef __OBJC__
+#include "cocoa/main.h"
+#else
 #include "xlib/main.h"
 #endif
 #endif
+#endif

 #include "sized_string.h"
 #include "ui_i18n_decls.h"
@@ -121,16 +210,12 @@ typedef struct edit_change EDIT_CHANGE;
 #include "ui_dropdown.h"

 volatile _Bool tox_thread_init, audio_thread_init, video_thread_init, toxav_thread_init;
+volatile _Bool logging_enabled, audible_notifications_enabled, audio_filtering_enabled, close_to_tray, start_in_tray, auto_startup;
+volatile uint16_t loaded_audio_in_device, loaded_audio_out_device;
 _Bool tox_connected;

 _Bool audio_preview, video_preview;

-volatile _Bool logging_enabled, audible_notifications_enabled, audio_filtering_enabled, close_to_tray, start_in_tray;
-
-volatile uint16_t loaded_audio_in_device, loaded_audio_out_device;
-
-#define MAX_NUM_FRIENDS 256
-#define MAX_NUM_GROUPS 512

 //friends and groups
 //note: assumes array size will always be large enough
@@ -142,15 +227,6 @@ uint32_t friends, groups;
 int utox_window_width, utox_window_height, utox_window_baseline;
 _Bool utox_window_maximized;

-enum
-{
-    CURSOR_NONE,
-    CURSOR_TEXT,
-    CURSOR_HAND,
-    CURSOR_SELECT,
-    CURSOR_ZOOM_IN,
-    CURSOR_ZOOM_OUT,
-};
 uint8_t cursor;

 _Bool mdown;
@@ -168,68 +244,8 @@ uint16_t video_width, video_height, max_video_width, max_video_height;
 char proxy_address[256];
 extern struct Tox_Options options;

-enum
-{
-    FONT_TEXT,
-    FONT_TITLE,
-
-    /*FONT_MSG,
-    FONT_MSG_NAME,
-    FONT_MSG_LINK,*/
-
-    FONT_SELF_NAME,
-    FONT_STATUS,
-    FONT_LIST_NAME,
-
-    FONT_MISC,
-};
-
-//sysmenu icons
-enum
-{
-    BM_ONLINE = 1,
-    BM_AWAY,
-    BM_BUSY,
-    BM_OFFLINE,
-    BM_STATUS_NOTIFY,
-
-    BM_ADD,
-    BM_GROUPS,
-    BM_TRANSFER,
-    BM_SETTINGS,
-
-    BM_LBUTTON,
-    BM_SBUTTON,
-
-    BM_CONTACT,
-    BM_GROUP,
-
-    BM_FILE,
-    BM_CALL,
-    BM_VIDEO,
-
-    BM_FT,
-    BM_FTM,
-    BM_FTB1,
-    BM_FTB2,
-
-    BM_NO,
-    BM_PAUSE,
-    BM_RESUME,
-    BM_YES,
-
-    BM_SCROLLHALFTOP,
-    BM_SCROLLHALFBOT,
-    BM_STATUSAREA,
-
-    BM_CB1,
-    BM_CB2,
-    BM_CHAT_SEND,
-    BM_CHAT_SEND_OVERLAY,
-    BM_CI1
-};
-
-#define isdesktop(x) ((size_t)(x) == 1)
+// inserts/deletes a value into the registry to launch uTox after boot
+void launch_at_startup(int is_launch_at_startup);

 void drawalpha(int bm, int x, int y, int width, int height, uint32_t color);
 void loadalpha(int bm, void *data, int width, int height);
@@ -298,6 +314,8 @@ struct
 //add friend page
 uint8_t addfriend_status;

+_Bool dont_send_typing_notes; //Stores user's preference about typing notifications
+
 const char *tox_savename; //Stores current name of tox's savefile

 #define BORDER 1
@@ -346,11 +364,12 @@ int datapath_old(uint8_t *dest);
 int datapath(uint8_t *dest);
 int datapath_subdir(uint8_t *dest, const char *subdir);
 void flush_file(FILE *file);
-int resize_file(FILE *file, uint64_t size);
 int ch_mod(uint8_t *file);
 int file_lock(FILE *file, uint64_t start, size_t length);
 int file_unlock(FILE *file, uint64_t start, size_t length);

+/* OS-specific cleanup function for when edits are defocused. Commit IME state, etc. */
+void edit_will_deactivate(void);

 /** Creates a tray baloon popup with the message, and flashes the main window
  *

and this can be merged

SmoothDude commented 9 years ago

Fixed, can be automatically merged now.

irungentoo commented 9 years ago

This makes the save a bit too easy to accidentally break and breaks saving on OSX and android.

The tox save name should be set to "tox_save" as default in tox.c instead of in the (xlib, windows, etc..) wrappers.

SmoothDude commented 9 years ago

You're absolutely right, It is gonna be fixed shortly.

GrayHatter commented 9 years ago
SmoothDude commented 9 years ago

Is squashing really good idea ? Commit history will be rewritten and in not good way.

GrayHatter commented 9 years ago

@SmoothDude I don't want to you squash down anything except all the merge commits. according to GH there's 5 merge commits in a row. Maybe GH is wrong and it looks normal in an actual repo?

irungentoo commented 9 years ago

The issue I have with this is that it makes breaking the save really easy (this PR breaks it on android and OSX for example).

I would suggest you set the default name (tox_save) in the tox thread if no name is set or something.

SmoothDude commented 9 years ago

Already done: https://github.com/SmoothDude/uTox/commit/4cae00d22f7c8f046de26ecd1bf633fd9960397b

GrayHatter commented 9 years ago

@SmoothDude can you also add OSX support in cocoa? @stal888 can :+1: if you need someone to test it out.

SmoothDude commented 9 years ago

I don't use OS X, can implement it, but cannot test it.

stal888 commented 9 years ago

oops, can't read

Sent from my iPhone

On Jun 11, 2015, at 08:59, SmoothDude notifications@github.com wrote:

I don't use OS X, probably cannot help here.

― Reply to this email directly or view it on GitHub.

GrayHatter commented 9 years ago

@SmoothDude Okay you can ignore the line comments that I struckout, this looks fine once I get a change to test it and @stal888 give me a :+1: it'll be good to merge

GrayHatter commented 9 years ago
SmoothDude commented 9 years ago

Will it better to make it search for profile in directory, it was given to --profile or should I leave everything as it ?

With memory check strings, hmm. strlen(string) always returns length of the string without NULL character, so it have to always be here, since string isn't going to suddenly change in the middle. Can force it to assign NULL character at tox_savename_len+1 to make it 100% sure, it will never overrun buffer.

About legacy support, still cannot understand what I have to do here dude. Explain please what exactly do you want from me or provide patch after 2 problems gonna be solved.

GrayHatter commented 9 years ago

I'll provide a patch for legacy support next time I pull your branch.

So tox profiles are 'supposed' to end with .tox did you expect users to use --profile default.tox or --profile default? And the follow up, did you intend for --profile default to enable the user to use the default.tox save file?

I ask because with the way your PR is now, If I copy over my default.tox profile that I got from qtox, and use --profile default.tox what utox will try to use is default.tox.tox

GrayHatter commented 9 years ago

After reading your comment, I realise that I'm looking at the wrong side of things. I was worried about a user string that is too long for utox. But the place it fix that is not tox.c but when we get the string. You can ignore that one as well. The only thing I need currently is the .tox extension mentioned one comment up.

SmoothDude commented 9 years ago

Done with .tox extension

GrayHatter commented 9 years ago

@SmoothDude apply this patch

diff --git a/tox.c b/tox.c
index 7523ebb..b592320 100644
--- a/tox.c
+++ b/tox.c
@@ -376,33 +376,37 @@ static size_t load_save(uint8_t **out_data){

     uint32_t size;
     const unsigned int tox_savename_len = strlen(tox_savename);
-    do{ /* Try the STS compliant save location */
-        p = path + datapath(path);
-        memcpy(savename, tox_savename, tox_savename_len);
-        memcpy(savename+tox_savename_len, ".tox", sizeof(".tox")); /* Add tox extension */
-        memcpy((char*)p, savename, tox_savename_len+sizeof(".tox"));
-        data = file_raw((char*)path, &size);
-        if(data) break; /* We have data, were done here! */
-        /* Try filename missing the .tox extension */
-        p = path + datapath(path);
-        memcpy((char*)p, tox_savename, tox_savename_len+1);
-        data = file_raw((char*)path, &size);
-        if(data) break;
-        /* That didn't work, do we have a backup? */
-        p = path + datapath(path);
-        memcpy(savename+tox_savename_len, ".tmp", sizeof(".tmp"));
-        memcpy((char*)p, savename, tox_savename_len+sizeof(".tmp"));
-        data = file_raw((char*)path, &size);
-        if(data) break;
-        /* No backup huh? Is it in an old location we support? */
-        p = path + datapath_old(path);
-        memcpy((char*)p, tox_savename, tox_savename_len+1);
-        data = file_raw((char*)path, &size);
-        if(data) break;
-        /* Well, lets try the current directory... */
-        data = file_raw(tox_savename, &size);
-        if(!data) return 0; /* F***it I give up! */
-    } while(0); /* Only once! */
+
+    /* Try the STS compliant save location */
+    p = path + datapath(path);
+    memcpy(savename, tox_savename, tox_savename_len);
+    memcpy(savename+tox_savename_len, ".tox", sizeof(".tox")); /* Add tox extension */
+    memcpy((char*)p, savename, tox_savename_len+sizeof(".tox"));
+    data = file_raw((char*)path, &size);
+    if(data) break; /* We have data, were done here! */
+    /* Try filename missing the .tox extension */
+    p = path + datapath(path);
+    memcpy((char*)p, tox_savename, tox_savename_len+1);
+    data = file_raw((char*)path, &size);
+    if(data) break;
+    /* That didn't work, do we have a backup?
+     * search for the atomic same file name incase we crashed while writing
+     * the save file to disk. */
+    p = path + datapath(path);
+    memcpy(savename+tox_savename_len, ".tmp", sizeof(".tmp"));
+    memcpy((char*)p, savename, tox_savename_len+sizeof(".tmp"));
+    data = file_raw((char*)path, &size);
+    if(data) break;
+    /* No backup huh? Is it in an old location we support?
+     * These next 3 are for legacy support, ideally no one still uses this
+     * location, but let's just be sure. */
+    p = path + datapath_old(path);
+    strcpy((char*)p, "tox_save");
+    data = file_raw((char*)path, &size);
+    if(data) break;
+    /* Well, lets try the current directory... */
+    data = file_raw(tox_savename, &size);
+    if(!data) return 0; /* F***it I give up! */

     *out_data = data;
     return size;

then once you give it one last test @ irungentoo and he'll merge this once he can test it out

SmoothDude commented 9 years ago

Patch merged

stal888 commented 9 years ago

@GrayHatter the do-while loop seemed important...

SmoothDude commented 9 years ago

Thank you stal888 for mentioning it.

GrayHatter commented 9 years ago

I'm glad one of you were smart enough to actually read the code... It is, or it was... this really should be an ifelse tree if you want to rewrite it @SmoothDude, else can you just restore the do{ and the }while(0)?

SmoothDude commented 9 years ago

Restored already, but isn't hard to rewrite though if it is required.