/[winpt]/trunk/Src/wptW32API.cpp
ViewVC logotype

Diff of /trunk/Src/wptW32API.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 205 by twoaday, Thu Apr 27 12:46:03 2006 UTC revision 255 by twoaday, Tue Aug 1 16:37:23 2006 UTC
# Line 306  make_filename (const char *path, const c Line 306  make_filename (const char *path, const c
306      char *p;      char *p;
307      size_t size = 0;      size_t size = 0;
308    
309      if( path && *path )      if (path && *path)
310          size += strlen( path );          size += strlen (path);
311      if( file && *file )      if (file && *file)
312          size += strlen( file );          size += strlen (file);
313      if( ext && *ext )      if( ext && *ext )
314          size += strlen( ext );          size += strlen( ext );
315      p = new char[size + 4];      p = new char[size + 4];
316        if (!p)
317            BUG (0);
318      memset( p, 0, size );      memset( p, 0, size );
319      if( path ) {      if( path ) {
320          strcat( p, path );          strcat( p, path );
# Line 503  int Line 505  int
505  get_file_version (const char *fname, WORD *major, WORD *minor,  get_file_version (const char *fname, WORD *major, WORD *minor,
506                    WORD *patch1, WORD *patch2)                    WORD *patch1, WORD *patch2)
507  {  {
508      VS_FIXEDFILEINFO *inf = {0};      VS_FIXEDFILEINFO *inf;
509      char file[MAX_PATH+1] = {0};      char file[MAX_PATH+1] = {0};
510      LPVOID buf, data;      LPVOID buf, data;
511      DWORD arg;      DWORD arg;
# Line 514  get_file_version (const char *fname, WOR Line 516  get_file_version (const char *fname, WOR
516      size = GetFileVersionInfoSize (file, &arg);      size = GetFileVersionInfoSize (file, &arg);
517      if (!size)      if (!size)
518          return -1;          return -1;
519      buf = (LPVOID)new CHAR[size];      buf = (LPVOID)new char[size];
520      if (!buf)      if (!buf)
521          BUG (NULL);          BUG (NULL);
522      GetFileVersionInfo (file, 0, size, buf);      GetFileVersionInfo (file, 0, size, buf);
# Line 522  get_file_version (const char *fname, WOR Line 524  get_file_version (const char *fname, WOR
524      qlen=0;      qlen=0;
525      VerQueryValue (buf, "\\", &data, &qlen);      VerQueryValue (buf, "\\", &data, &qlen);
526      if (!qlen) {      if (!qlen) {
527          delete [] (char*)buf;          delete [](char*)buf;
528          return -1;          return -1;
529      }      }
530      inf = (VS_FIXEDFILEINFO*)data;      inf = (VS_FIXEDFILEINFO*)data;
# Line 536  get_file_version (const char *fname, WOR Line 538  get_file_version (const char *fname, WOR
538      if (patch2)      if (patch2)
539          *patch2 = LOWORD (inf->dwProductVersionLS);          *patch2 = LOWORD (inf->dwProductVersionLS);
540    
541      delete [] (char*)buf;      delete [](char*)buf;
542      return 0;      return 0;
543  }  }
544    
# Line 634  GetDlgItemText_utf8 (HWND dlg, int id, c Line 636  GetDlgItemText_utf8 (HWND dlg, int id, c
636  }  }
637    
638    
639  struct reminder_hd_s {  /* Return TRUE if the current user has admin privileges. */
640      int msecs;  BOOL
641      HWND dlg;  user_is_admin (void)
     HANDLE hd;  
 };  
   
   
 static DWORD CALLBACK  
 foreground_reminder_thread (void *c)  
642  {  {
643      struct reminder_hd_s *ctx = (struct reminder_hd_s *)c;      SID_IDENTIFIER_AUTHORITY SystemSidAuthority = SECURITY_NT_AUTHORITY;
644      Sleep (ctx->msecs);      HANDLE hd;
645      SetForegroundWindow (ctx->dlg);      TOKEN_GROUPS  *ptg = NULL;
646      CloseHandle (ctx->hd);      DWORD ngtoken;
647      delete ctx;      DWORD i;
648      ExitThread (0);      BOOL admin = FALSE;
649      return 0;      PSID psid = 0;
650  }  
651        if (GetVersion () & 0x80000000) /* Win9X */
652  /* Try to force the window @dlg to the foreground.          return TRUE;
653     On NT5 or later this will not work if the user  
654     is working in another window (console for example). */      if (!OpenThreadToken (GetCurrentThread (), TOKEN_QUERY, FALSE, &hd) &&
655  void          !OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &hd))
656  force_foreground_window (HWND dlg, int msecs)          return FALSE;
657  {      
658      struct reminder_hd_s *hd;      if (!GetTokenInformation (hd, TokenGroups, NULL, 0, &ngtoken) &&
659      DWORD tid;          GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
660            ptg = (TOKEN_GROUPS*)GlobalAlloc (GPTR, ngtoken);
661            if (!ptg)
662                return FALSE;
663    
664            if (!GetTokenInformation (hd, TokenGroups,
665                                      ptg, ngtoken, &ngtoken)) {
666                GlobalFree (ptg);
667                return FALSE;
668            }
669            AllocateAndInitializeSid (&SystemSidAuthority,
670                                      2, SECURITY_BUILTIN_DOMAIN_RID,
671                                      DOMAIN_ALIAS_RID_ADMINS,
672                                      0, 0, 0, 0, 0, 0,
673                                      &psid);
674            for (i = 0; i < ptg->GroupCount; i++) {
675                if (EqualSid (ptg->Groups[i].Sid, psid)) {
676                    admin = TRUE;
677                    break;
678                }
679            }
680            FreeSid (psid);
681            GlobalFree (ptg);
682        }
683    
684      hd = new reminder_hd_s;      CloseHandle (hd);
685      hd->dlg = dlg;      return admin;
     hd->msecs = msecs;  
     hd->hd = CreateThread (NULL, 0, foreground_reminder_thread,  
                            hd, NULL, &tid);  
686  }  }

Legend:
Removed from v.205  
changed lines
  Added in v.255

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26