Revision: 78045
          http://sourceforge.net/p/brlcad/code/78045
Author:   starseeker
Date:     2021-01-06 17:29:09 +0000 (Wed, 06 Jan 2021)
Log Message:
-----------
Adjust GUI apps default working dir to HOME.

When launched from a system installed location via icon, the default
working directory of MGED, Archer and rtwizard gets set to the bin
directory that holds the executable.  This is typically a read-only
location, which results in a variety of problems when trying to run
various commands.

The most typical case where this is a problem is Windows desktop and
start menu shortcuts.  The NSIS installer has a way to adjust the
directory, but the MSI installer generated by WiX is a tougher nut to
crack.  Various experiments have so far failed to identify a working
approach to adjusting the shortcut startup directories with CMake/WiX.
Using Windows bat files as launchers works, but using them with the
MSI installer results in incorrect icons for the desktop shortcuts
with no obvious way to override them.

Rather than continue to jump through hoops, just set the working dir
directly to the user's home directory when these three applications
are invoked without arguments.  This should preserve all existing
behaviors for any scripting cases, but will avoid a read-only working
directory when using the no-args launch produced by desktop shortcuts.

Modified Paths:
--------------
    brlcad/trunk/NEWS
    brlcad/trunk/src/archer/archer.c
    brlcad/trunk/src/mged/CMakeLists.txt
    brlcad/trunk/src/mged/mged.c
    brlcad/trunk/src/rtwizard/CMakeLists.txt
    brlcad/trunk/src/rtwizard/main.c

Removed Paths:
-------------
    brlcad/trunk/src/archer/archer.bat
    brlcad/trunk/src/mged/mged.bat
    brlcad/trunk/src/rtwizard/rtwizard.bat

Modified: brlcad/trunk/NEWS
===================================================================
--- brlcad/trunk/NEWS   2021-01-06 13:54:19 UTC (rev 78044)
+++ brlcad/trunk/NEWS   2021-01-06 17:29:09 UTC (rev 78045)
@@ -13,6 +13,9 @@
 --- 2020-xx-xx  Release 7.32.2                                     ---
 ----------------------------------------------------------------------
 
+* updated Archer to set cwd=HOME when run without args - Cliff Yapp
+* updated rtwizard to set cwd=HOME when run without args - Cliff Yapp
+* updated MGED to set cwd=HOME when run without args - Cliff Yapp
 * fixed reporting of MGED "vars" command - Cliff Yapp
 * updated MGED to not open non-.g-files as databases - Cliff Yapp
 * fixed problems with command I/O management in MGED - Cliff Yapp

Deleted: brlcad/trunk/src/archer/archer.bat
===================================================================
--- brlcad/trunk/src/archer/archer.bat  2021-01-06 13:54:19 UTC (rev 78044)
+++ brlcad/trunk/src/archer/archer.bat  2021-01-06 17:29:09 UTC (rev 78045)
@@ -1,31 +0,0 @@
-REM                       A R C H E R . B A T
-REM  BRL-CAD
-REM
-REM  Copyright (c) 2006-2021 United States Government as represented by
-REM  the U.S. Army Research Laboratory.
-REM
-REM  This library is free software; you can redistribute it and/or
-REM  modify it under the terms of the GNU Lesser General Public License
-REM  version 2.1 as published by the Free Software Foundation.
-REM
-REM  This library is distributed in the hope that it will be useful, but
-REM  WITHOUT ANY WARRANTY; without even the implied warranty of
-REM  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-REM  Lesser General Public License for more details.
-REM
-REM  You should have received a copy of the GNU Lesser General Public
-REM  License along with this file; see the file named COPYING for more
-REM  information.
-REM
-
-@ECHO OFF
-
-SETLOCAL
-
-SET PATH=%~dp0;%PATH%
-SET ARCHER=%~dp0archer
-
-PUSHD %USERPROFILE%
-START /B "" "%ARCHER%" %*
-
-EXIT

Modified: brlcad/trunk/src/archer/archer.c
===================================================================
--- brlcad/trunk/src/archer/archer.c    2021-01-06 13:54:19 UTC (rev 78044)
+++ brlcad/trunk/src/archer/archer.c    2021-01-06 17:29:09 UTC (rev 78045)
@@ -22,6 +22,10 @@
 
 #include <string.h>
 
+#ifdef HAVE_WINDOWS_H
+#  include <direct.h> /* For chdir */
+#endif
+
 #include "bresource.h"
 #include "bnetwork.h"
 #include "bio.h"
@@ -66,6 +70,17 @@
 
     /* initialize progname for run-tim resource finding */
     bu_setprogname(argv[0]);
+
+    /* Change the working directory to BU_DIR_HOME if we are invoking
+     * without any arguments. */
+    if (argc == 1) {
+       const char *homed = bu_dir(NULL, 0, BU_DIR_HOME, NULL);
+       if (homed && chdir(homed)) {
+           bu_exit(1, "Failed to change working directory to \"%s\" ", homed);
+       }
+    }
+
+    /* initialize Tcl args */
     bu_vls_sprintf(&tcl_cmd, "set argv0 %s", argv[0]);
     (void)Tcl_Eval(interp, bu_vls_addr(&tcl_cmd));
     bu_vls_sprintf(&tcl_cmd, "set ::no_bwish 1");

Modified: brlcad/trunk/src/mged/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/mged/CMakeLists.txt        2021-01-06 13:54:19 UTC (rev 
78044)
+++ brlcad/trunk/src/mged/CMakeLists.txt        2021-01-06 17:29:09 UTC (rev 
78045)
@@ -95,15 +95,11 @@
     add_dependencies(mged ${item})
   endforeach(item ${tclindex_target_list})
 
-  # The bat file is used to set the working directory for shortcuts in MSIS
-  # installers generated with WiX.
-  BRLCAD_MANAGE_FILES("mged.bat" ${BIN_DIR} EXEC)
-
   # MGED is one of the programs that gets a start menu entry
-  set_property(INSTALL "${BIN_DIR}/mged.bat"
+  set_property(INSTALL "${BIN_DIR}/$<TARGET_FILE_NAME:mged>"
     PROPERTY CPACK_START_MENU_SHORTCUTS "MGED ${BRLCAD_VERSION}"
     )
-  set_property(INSTALL "${BIN_DIR}/mged.bat"
+  set_property(INSTALL "${BIN_DIR}/$<TARGET_FILE_NAME:mged>"
     PROPERTY CPACK_DESKTOP_SHORTCUTS "MGED ${BRLCAD_VERSION}"
     )
 

Deleted: brlcad/trunk/src/mged/mged.bat
===================================================================
--- brlcad/trunk/src/mged/mged.bat      2021-01-06 13:54:19 UTC (rev 78044)
+++ brlcad/trunk/src/mged/mged.bat      2021-01-06 17:29:09 UTC (rev 78045)
@@ -1,30 +0,0 @@
-REM                      M G E D . B A T
-REM  BRL-CAD
-REM
-REM  Copyright (c) 2006-2021 United States Government as represented by
-REM  the U.S. Army Research Laboratory.
-REM
-REM  This library is free software; you can redistribute it and/or
-REM  modify it under the terms of the GNU Lesser General Public License
-REM  version 2.1 as published by the Free Software Foundation.
-REM
-REM  This library is distributed in the hope that it will be useful, but
-REM  WITHOUT ANY WARRANTY; without even the implied warranty of
-REM  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-REM  Lesser General Public License for more details.
-REM
-REM  You should have received a copy of the GNU Lesser General Public
-REM  License along with this file; see the file named COPYING for more
-REM  information.
-REM
-
-@ECHO OFF
-
-SETLOCAL
-
-SET PATH=%~dp0;%PATH%
-SET MGED=%~dp0mged
-
-START /B "" "%MGED%" -W ~ %*
-
-EXIT

Modified: brlcad/trunk/src/mged/mged.c
===================================================================
--- brlcad/trunk/src/mged/mged.c        2021-01-06 13:54:19 UTC (rev 78044)
+++ brlcad/trunk/src/mged/mged.c        2021-01-06 17:29:09 UTC (rev 78045)
@@ -1042,7 +1042,6 @@
 #endif
 
     char *attach = (char *)NULL;
-    char *wdir = (char *)NULL;
 
     setmode(fileno(stdin), O_BINARY);
     setmode(fileno(stdout), O_BINARY);
@@ -1067,7 +1066,7 @@
 #endif
 
     bu_optind = 1;
-    while ((c = bu_getopt(argc, argv, "a:d:hbicorx:X:vW:?")) != -1) {
+    while ((c = bu_getopt(argc, argv, "a:d:hbicorx:X:v?")) != -1) {
        if (bu_optopt == '?') c='h';
        switch (c) {
            case 'a':
@@ -1109,9 +1108,6 @@
                bu_log("WARNING: -o is a developer option and subject to 
change.  Do not use.\n");
                old_mged_gui = 0;
                break;
-           case 'W':
-               wdir = bu_optarg;
-               break;
            default:
                bu_log("Unrecognized option (%c)\n", bu_optopt);
                /* fall through */
@@ -1120,21 +1116,13 @@
        }
     }
 
-    /* Change the working directory, if the user specified one */
-    if (wdir) {
-       struct bu_vls wldir = BU_VLS_INIT_ZERO;
-       /* Make sure '~' is always interpreted as the home directory */
-       if (BU_STR_EQUAL(wdir, "~")) {
-           const char *homed = bu_dir(NULL, 0, BU_DIR_HOME, NULL);
-           bu_vls_sprintf(&wldir, "%s", homed);
-       } else {
-           bu_vls_sprintf(&wldir, "%s", wdir);
+    /* Change the working directory to BU_DIR_HOME if we are invoking
+     * without any arguments. */
+    if (argc == 1) {
+       const char *homed = bu_dir(NULL, 0, BU_DIR_HOME, NULL);
+       if (homed && chdir(homed)) {
+           bu_exit(1, "Failed to change working directory to \"%s\" ", homed);
        }
-       if (chdir(bu_vls_cstr(&wldir))) {
-           bu_vls_free(&wldir);
-           bu_exit(1, "Failed to change working directory to \"%s\" ", wdir);
-       }
-       bu_vls_free(&wldir);
     }
 
     /* skip the args and invocation name */

Modified: brlcad/trunk/src/rtwizard/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/rtwizard/CMakeLists.txt    2021-01-06 13:54:19 UTC (rev 
78044)
+++ brlcad/trunk/src/rtwizard/CMakeLists.txt    2021-01-06 17:29:09 UTC (rev 
78045)
@@ -26,15 +26,11 @@
     add_dependencies(rtwizard ${item})
   endforeach(item ${tclindex_target_list})
 
-  # The bat file is used to set the working directory for shortcuts in MSIS
-  # installers generated with WiX.
-  BRLCAD_MANAGE_FILES("rtwizard.bat" ${BIN_DIR} EXEC)
-
   # RtWizard is one of the programs that gets a start menu entry
-  set_property(INSTALL "${BIN_DIR}/rtwizard.bat"
+  set_property(INSTALL "${BIN_DIR}/$<TARGET_FILE_NAME:rtwizard>"
     PROPERTY CPACK_START_MENU_SHORTCUTS "RtWizard ${BRLCAD_VERSION}"
     )
-  set_property(INSTALL "${BIN_DIR}/rtwizard.bat"
+  set_property(INSTALL "${BIN_DIR}/$<TARGET_FILE_NAME:rtwizard>"
     PROPERTY CPACK_DESKTOP_SHORTCUTS "RtWizard ${BRLCAD_VERSION}"
     )
 

Modified: brlcad/trunk/src/rtwizard/main.c
===================================================================
--- brlcad/trunk/src/rtwizard/main.c    2021-01-06 13:54:19 UTC (rev 78044)
+++ brlcad/trunk/src/rtwizard/main.c    2021-01-06 17:29:09 UTC (rev 78045)
@@ -949,12 +949,10 @@
     int need_help_dev = 0;
     int uac = 0;
 
-    struct bu_vls wdir = BU_VLS_INIT_ZERO;
-
     struct bu_vls optparse_msg = BU_VLS_INIT_ZERO;
     struct bu_vls info_msg = BU_VLS_INIT_ZERO;
     struct rtwizard_settings *s = rtwizard_settings_create();
-    struct bu_opt_desc d[36];
+    struct bu_opt_desc d[35];
 
     BU_OPT(d[0],  "h", "help",          "",          NULL,            
&need_help,    "Print help and exit");
     BU_OPT(d[1],  "",  "help-dev",      "",          NULL,            
&need_help_dev,    "Print options intended for developer/programmatic use and 
exit.");
@@ -990,13 +988,21 @@
     BU_OPT(d[31], "v", "verbose",       "#",         &bu_opt_int,     
&s->verbose,      "Verbosity");
     BU_OPT(d[32], "",  "log-file",      "filename",  &bu_opt_vls,     
s->log_file,      "Log debugging output to this file");
     BU_OPT(d[33], "",  "pid-file",      "filename",  &bu_opt_vls,     
s->pid_file,      "File used to communicate PID numbers (for app developers)");
-    BU_OPT(d[34], "",  "working-dir",   "path",   &bu_opt_vls,     &wdir,      
"Specify a working directory");
-    BU_OPT_NULL(d[35]);
+    BU_OPT_NULL(d[34]);
 
     /* initialize progname for run-time resource finding */
     bu_setprogname(argv[0]);
     av0 = argv[0];
 
+    /* Change the working directory to BU_DIR_HOME if we are invoking
+     * without any arguments. */
+    if (argc == 1) {
+       const char *homed = bu_dir(NULL, 0, BU_DIR_HOME, NULL);
+       if (homed && chdir(homed)) {
+           bu_exit(1, "Failed to change working directory to \"%s\" ", homed);
+       }
+    }
+
     /* Skip first arg */
     argv++; argc--;
 
@@ -1017,18 +1023,6 @@
        bu_exit(EXIT_SUCCESS, NULL);
     }
 
-    if (bu_vls_strlen(&wdir)) {
-       /* Make sure '~' is always interpreted as the home directory */
-       if (BU_STR_EQUAL(bu_vls_cstr(&wdir), "~")) {
-           const char *homed = bu_dir(NULL, 0, BU_DIR_HOME, NULL);
-           bu_vls_sprintf(&wdir, "%s", homed);
-       }
-       if (chdir(bu_vls_cstr(&wdir))) {
-           bu_exit(EXIT_FAILURE, "Failed to change working directory to \"%s\" 
", bu_vls_cstr(&wdir));
-       }
-    }
-    bu_vls_free(&wdir);
-
     {
        int stop = 0;
        for (i = 0; i < uac; i++) {

Deleted: brlcad/trunk/src/rtwizard/rtwizard.bat
===================================================================
--- brlcad/trunk/src/rtwizard/rtwizard.bat      2021-01-06 13:54:19 UTC (rev 
78044)
+++ brlcad/trunk/src/rtwizard/rtwizard.bat      2021-01-06 17:29:09 UTC (rev 
78045)
@@ -1,30 +0,0 @@
-REM                    R T W I Z A R D . B A T
-REM  BRL-CAD
-REM
-REM  Copyright (c) 2006-2021 United States Government as represented by
-REM  the U.S. Army Research Laboratory.
-REM
-REM  This library is free software; you can redistribute it and/or
-REM  modify it under the terms of the GNU Lesser General Public License
-REM  version 2.1 as published by the Free Software Foundation.
-REM
-REM  This library is distributed in the hope that it will be useful, but
-REM  WITHOUT ANY WARRANTY; without even the implied warranty of
-REM  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-REM  Lesser General Public License for more details.
-REM
-REM  You should have received a copy of the GNU Lesser General Public
-REM  License along with this file; see the file named COPYING for more
-REM  information.
-REM
-
-@ECHO OFF
-
-SETLOCAL
-
-SET PATH=%~dp0;%PATH%
-SET RTWIZARD=%~dp0rtwizard
-
-START /B "" "%RTWIZARD%" --working-dir ~ %*
-
-EXIT

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to