Пример #1
0
//z 获取当前登录用户名
char *
pwd_cuserid (char *where)
{
    char buf[32], *ptr;
    int len = sizeof (buf);
    //z 使用了多种方式来获取 user name 。
    if (GetUserName (buf, (LPDWORD) &len) == TRUE)
    {
        ;
    }
    else if (!!(ptr = getenv ("USERNAME")))
    {
        strcpy (buf, ptr);
    }
    else if (!read_registry (HKEY_LOCAL_MACHINE, "Network\\Logon",
                             "username", buf, &len))
    {
        return NULL;
    }
    if (where)
    {
        strncpy (where, buf, len);
        return where;
    }
    return xstrdup (buf);
}
Пример #2
0
/* locate vcvars32.bat */
void find_vcvars()
{
   char data[256], name[256];
   int i;

   /* look in the registry (try VC versions 4 through 9, just in case :-) */
   for (i=9; i>=4; i--) {
      sprintf(name, "Software\\Microsoft\\DevStudio\\%d.0\\Products\\Microsoft Visual C++", i);

      if (read_registry(name, "ProductDir", data, sizeof(data))) {
	 strcat(data, "\\bin\\vcvars32.bat");

	 if (access(data, 4) == 0) {
	    printf("Found %s\n", data);
	    break;
	 }
      }

      data[0] = 0;
   }

   /* oh dear, have to ask the user where they put it */
   if (!data[0]) {
      printf("\n  Unable to find MSVC ProductDir information in your registry!\n\n");
      printf("  To install Allegro, I need to know the path where your compiler is\n");
      printf("  installed. Somewhere in your MSVC installation directory there will\n");
      printf("  be a file called vcvars32.bat, which contains this information.\n");
      printf("  Please enter the full path to where I can find that file, for example\n");
      printf("  c:\\Program Files\\Microsoft Visual Studio\\VC98\\bin\\vcvars32.bat\n");

      for (;;) {
	 printf("\n> ");
	 fflush(stdout);

	 if (gets(data)) {
	    i = strlen(data) - 12;
	    if (i < 0)
	       i = 0;

	    if (stricmp(data+i, "vcvars32.bat") != 0)
	       printf("\nError: that path doesn't end in vcvars32.bat!\n");
	    else if (access(data, 4) != 0)
	       printf("\nError: can't find a vcvars32.bat file there!\n");
	    else {
	       printf("\nUsing %s\n", data);
	       break;
	    }
	 }

	 data[0] = 0;
      }
   }

   /* put it in the environment */
   strcpy(name, "VCVARS=");
   strcat(name, data);

   putenv(name);
}