Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

win32vmdstart.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the
00004  *cr                        University of Illinois
00005  *cr                         All Rights Reserved
00006  *cr
00007  ***************************************************************************/
00008 /***************************************************************************
00009  * RCS INFORMATION:
00010  *
00011  *      $RCSfile: win32vmdstart.c,v $
00012  *      $Author: johns $        $Locker:  $             $State: Exp $
00013  *      $Revision: 1.52 $      $Date: 2020/12/14 20:26:02 $
00014  *
00015  ***************************************************************************/
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <windows.h>
00024 
00025 #define VMD_FILENAME_MAX 1024
00026 
00027 static char * vmd_get_vmddir(void) {
00028   LONG res = ERROR_FILE_NOT_FOUND;
00029   HKEY k;
00030   BYTE * vmddir;
00031   DWORD bufsz;
00032   DWORD buftype;
00033 
00034 #if defined(_WIN64)
00035   const char *vmdregkey = "Software\\University of Illinois\\VMD\\1.9.4";
00036 #else
00037   const char *vmdregkey = "Software\\University of Illinois\\VMD\\x86\\1.9.4";
00038 #endif
00039   res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, vmdregkey, 0, KEY_READ, &k);
00040   if (res != ERROR_SUCCESS)  {
00041     printf("Failed to find registry key: '%s'.\n", vmdregkey);
00042     return NULL;
00043   }
00044 
00045   bufsz = 2048;
00046   vmddir = (BYTE *) malloc(2048);
00047 
00048   res = RegQueryValueEx(k, "VMDDIR", NULL, &buftype, vmddir, &bufsz);
00049 
00050   if (res != ERROR_SUCCESS) {
00051     printf("Failed to get VMDDIR registry key value.\n");
00052     free(vmddir);
00053     vmddir = NULL;
00054   }
00055 
00056   if (buftype != REG_SZ) {
00057     printf("Bad data type in VMDDIR registry key value\n");
00058     free(vmddir);
00059     vmddir = NULL;
00060   }
00061 
00062   return (char *) vmddir;
00063 }
00064 
00065 #if defined(VMDSEPARATESTARTUP)
00066 // used when seperate startup (for shell) is needed
00067 int main(int argc, char **argv) {
00068 #else
00069 // called by VMD main program
00070 int win32vmdstart(void) {
00071 #endif
00072 
00073   int i, j, len;
00074   char *str, *str2, *vmddir;
00075   char tmp[MAX_PATH + 8192];
00076   char buffer[MAX_PATH +1];
00077   int usedregistry;
00078 #if defined(VMDSEPARATESTARTUP)
00079   int rc;
00080 #endif
00081 
00082 /* XXX debugging hacks to be sure the compiler mode is set correctly */
00083 #if 0 && defined(_WIN64)
00084   printf("TEST: Windows x64 VMD test build.\n");
00085   printf("TEST: sizeof(int): %d  sizeof(long): %d  sizeof(void *): %d\n", 
00086     sizeof(int), sizeof(long), sizeof(void *));
00087 #endif 
00088 
00089   vmddir = NULL;             // initialize to NULL for safety
00090   usedregistry = 1;          // change this to 0 if we fail
00091   vmddir = vmd_get_vmddir(); // search Windows registry first 
00092 
00093   if (vmddir == NULL) {
00094 #if 1
00095     // get full pathname to VMD executable
00096     GetModuleFileName(NULL, buffer, sizeof(buffer));
00097     usedregistry = 0;  // registry failed, we had to guess, using exe path
00098     vmddir = buffer;   // get from the Win32 API vmd.exe path
00099 #elif defined(VMDSEPARATESTARTUP)
00100     // desparate attempt to get VMDDIR from argv[0], which only works if 
00101     // we were started from the explorer shell
00102     usedregistry = 0;  // registry failed, we had to guess, using exe path
00103     vmddir = argv[0];  // get from the explorer shell vmd.exe path
00104 #else
00105     return -1; // fail and exit
00106 #endif
00107   }
00108 
00109   len = strlen(vmddir);
00110   str = (char *) malloc(len);
00111   str2 = (char *) malloc(len);
00112   strcpy(str,  vmddir);
00113   strcpy(str2, vmddir);
00114 
00115   j=len;
00116   for (i=0; i<len; i++) {
00117     if (str[i] == '\\') {
00118       str2[i] = '/';
00119       j=i;
00120     }
00121   }
00122 
00123   if (usedregistry) {
00124     free(vmddir);  // free memory allocated by the vmd_get_vmddir() function
00125     vmddir = NULL; // make sure we don't accidentally use it again
00126   } else {  
00127     // If we didn't use the registry, we need to strip off everything after
00128     // and including the last "\" character. 
00129     // If we did use the registry, no string truncation is required.
00130     str[j] = '\0';
00131     str2[j] = '\0';
00132   }
00133 
00134   strcpy(tmp, "VMDDIR=");
00135   strcat(tmp, str2);
00136   putenv(strdup(tmp));
00137 
00138   strcpy(tmp, "TCL_LIBRARY=");
00139   strcat(tmp, str2);
00140   strcat(tmp, "/scripts/tcl");
00141   putenv(strdup(tmp));
00142 
00143   strcpy(tmp, "TK_LIBRARY=");
00144   strcat(tmp, str2);
00145   strcat(tmp, "/scripts/tk");
00146   putenv(strdup(tmp));
00147 
00148   if (!getenv("PYTHONPATH")) {
00149     strcpy(tmp, "PYTHONPATH=");
00150     strcat(tmp, str2);
00151     strcat(tmp, "/scripts/python");
00152     putenv(strdup(tmp));
00153   } else {
00154     strcpy(tmp, getenv("PYTHONPATH"));
00155     strcat(tmp, ":");
00156     strcat(tmp, str2);
00157     strcat(tmp, "/scripts/python");
00158     putenv(strdup(tmp));
00159   }
00160 
00161   strcpy(tmp, "VMDBABELBIN=");
00162   strcat(tmp, str);
00163   strcat(tmp, "\\babel\\babel.exe");
00164   putenv(strdup(tmp));
00165 
00166   strcpy(tmp, "BABEL_DIR=");
00167   strcat(tmp, str);
00168   strcat(tmp, "\\babel");
00169   putenv(strdup(tmp));
00170 
00171 #if defined(_WIN64)
00172   strcpy(tmp, "STRIDE_BIN=\"");
00173   strcat(tmp, str);
00174   strcat(tmp, "\\stride_WIN64.exe\"");
00175   putenv(strdup(tmp));
00176 
00177   strcpy(tmp, "SURF_BIN=");
00178   strcat(tmp, str);
00179   strcat(tmp, "\\surf_WIN64.exe");
00180   putenv(strdup(tmp));
00181 
00182   strcpy(tmp, "TACHYON_BIN=");
00183   strcat(tmp, str);
00184   strcat(tmp, "\\tachyon_WIN64.exe");
00185   putenv(strdup(tmp));
00186 #else
00187   strcpy(tmp, "STRIDE_BIN=\"");
00188   strcat(tmp, str);
00189   strcat(tmp, "\\stride_WIN32.exe\"");
00190   putenv(strdup(tmp));
00191 
00192   strcpy(tmp, "SURF_BIN=");
00193   strcat(tmp, str);
00194   strcat(tmp, "\\surf_WIN32.exe");
00195   putenv(strdup(tmp));
00196 
00197   strcpy(tmp, "TACHYON_BIN=");
00198   strcat(tmp, str);
00199   strcat(tmp, "\\tachyon_WIN32.exe");
00200   putenv(strdup(tmp));
00201 #endif
00202 
00203 #if defined(VMDSEPARATESTARTUP)
00204   strcpy(tmp, str);
00205   strcat(tmp, "\\winvmd.exe");
00206 
00207   // Add all of the command line options we may have had to the 
00208   // invocation of the real program.
00209   strcat(tmp, " ");
00210   for(i=1; i<argc; i++) {
00211     strcat(tmp, argv[i]);
00212     strcat(tmp, " ");
00213   }
00214 
00215   // Run the program!
00216   rc = WinExec(tmp, SW_SHOW);
00217   if (!rc) {
00218     printf("failed to start program %s\n", tmp);
00219     Sleep(10000);  
00220   }
00221 #endif
00222 
00223   return 0;
00224 }
00225 
00226 
00227 
00228 

Generated on Wed Apr 24 02:43:41 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002