/[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 278 by twoaday, Mon Jan 15 22:02:04 2007 UTC revision 376 by twoaday, Fri Dec 9 12:25:36 2011 UTC
# Line 1  Line 1 
1  /* wptW32API.cpp - Common W32 API functions  /* wptW32API.cpp - Common W32 API functions
2   *      Copyright (C) 2001, 2002, 2003, 2005, 2006 Timo Schulz   *      Copyright (C) 2001-2003, 2005-2006, 2009 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 32  Line 32 
32  #include "wptVersion.h"  #include "wptVersion.h"
33  #include "wptUTF8.h"  #include "wptUTF8.h"
34  #include "wptTypes.h"  #include "wptTypes.h"
35    #include "StringBuffer.h"
36    
37    
38  extern "C" void _SHFree (void *p);  extern "C" void _SHFree (void *p);
# Line 125  get_filename_dlg (HWND hwnd, int id, con Line 126  get_filename_dlg (HWND hwnd, int id, con
126                    const char *filter, const char *name)                    const char *filter, const char *name)
127  {  {
128      static char file[2*MAX_PATH+1] = "";      static char file[2*MAX_PATH+1] = "";
129        char _filter[512];
130      char workdir[MAX_PATH+1];      char workdir[MAX_PATH+1];
131      char *sel_file = NULL;      char *sel_file = NULL;
132      OPENFILENAME open;      OPENFILENAME open;
# Line 133  get_filename_dlg (HWND hwnd, int id, con Line 135  get_filename_dlg (HWND hwnd, int id, con
135          strcpy (file, name);          strcpy (file, name);
136      else      else
137          memset (file, 0, sizeof (file));          memset (file, 0, sizeof (file));
138      if (!filter)      if (!filter) {      
139          filter = "All Files (*.*)\0*.*\0\0";          strcpy (_filter, _("All Files (*.*)"));
140            memcpy (_filter+strlen (_filter)+1, "*.*\0\0", 5);
141            filter = _filter;
142        }
143    
144      GetCurrentDirectory (MAX_PATH, workdir);      GetCurrentDirectory (MAX_PATH, workdir);
145      memset (&open, 0, sizeof (open));      memset (&open, 0, sizeof (open));
# Line 179  get_fileopen_dlg (HWND hwnd, const char Line 184  get_fileopen_dlg (HWND hwnd, const char
184  const char*  const char*
185  get_folder_dlg (HWND hwnd, const char *title, const char *name)  get_folder_dlg (HWND hwnd, const char *title, const char *name)
186  {  {
187      static char folder[MAX_PATH+1] = "";      static char folder[2*MAX_PATH+1] = "";
188      BROWSEINFO bi;      BROWSEINFO bi;
189      ITEMIDLIST *il;      ITEMIDLIST *il;
190    
# Line 333  make_filename (const char *path, const c Line 338  make_filename (const char *path, const c
338  }  }
339    
340    
341  /* Generate a file name from a special dirctory. */  /* Generates a file name from a special dirctory. */
342  char*  char*
343  make_special_filename (int folder, const char *file, const char *ext)  make_special_filename (int folder, const char *file, const char *ext)
344  {  {
345      BOOL ec;      BOOL ec;
346      char path[MAX_PATH], *p;      char path[MAX_PATH+1], *p;
347      size_t n=0;      size_t n=0;
348    
349      /* MSDN: buf must be at least MAX_PATH=256 bytes */      /* MSDN: buf must be at least MAX_PATH=256 bytes */
# Line 488  center_window (HWND child, HWND parent) Line 493  center_window (HWND child, HWND parent)
493  }  }
494    
495    
 /* Retrieve the product verion of the given file @fname.  
    Format: MAJOR.MINOR.PATCH1.PATCH2  
    Return value: 0 on success. */  
 int  
 get_file_version (const char *fname,  
                   WORD *major, WORD *minor, WORD *patch1, WORD *patch2)  
 {  
     VS_FIXEDFILEINFO *inf;  
     char file[MAX_PATH+1] = {0};  
     LPVOID buf, data;  
     DWORD arg;  
     DWORD size;  
     UINT qlen;  
   
     strncpy (file, fname, MAX_PATH);  
     size = GetFileVersionInfoSize (file, &arg);  
     if (!size)  
         return -1;  
     buf = (LPVOID)new char[size];  
     if (!buf)  
         BUG (NULL);  
     GetFileVersionInfo (file, 0, size, buf);  
   
     qlen=0;  
     VerQueryValue (buf, "\\", &data, &qlen);  
     if (!qlen) {  
         delete [](char*)buf;  
         return -1;  
     }  
     inf = (VS_FIXEDFILEINFO*)data;  
   
     if (major)  
         *major = HIWORD (inf->dwProductVersionMS);  
     if (minor)  
         *minor = LOWORD (inf->dwProductVersionMS);  
     if (patch1)  
         *patch1 = HIWORD (inf->dwProductVersionLS);      
     if (patch2)  
         *patch2 = LOWORD (inf->dwProductVersionLS);  
   
     delete [](char*)buf;  
     return 0;  
 }  
496    
497    
498  /* Return date in a format which complies with the  /* Return date in a format which complies with the
# Line 607  get_temp_name (char *buf, DWORD buflen, Line 569  get_temp_name (char *buf, DWORD buflen,
569          name = tmp;          name = tmp;
570      }      }
571    
     /* In the mobile mode we need to use the current directory  
        as the temp path because no files should be stored outside  
        the USB disk drive. */  
 #ifdef WINPT_MOBILE  
     memset (buf, 0, buflen);  
     strncpy (buf, name, buflen-1);  
     return 0;  
 #endif  
   
572      if (!GetTempPath (buflen - strlen (name) -2, buf)) {      if (!GetTempPath (buflen - strlen (name) -2, buf)) {
573          log_debug ("GetTempPath() failed ec=%d\n", (int)GetLastError ());          log_debug ("GetTempPath() failed ec=%d\n", (int)GetLastError ());
574          return -1;          return -1;
# Line 667  GetDlgItemText_utf8 (HWND dlg, int id, c Line 620  GetDlgItemText_utf8 (HWND dlg, int id, c
620      return len;      return len;
621  }  }
622    
623    int
624    html_help_show (int map_id)
625    {
626        STARTUPINFO si;
627        PROCESS_INFORMATION pi;
628        SECURITY_ATTRIBUTES sec_attr;
629        char path[2*MAX_PATH+1];
630        
631        memset (&sec_attr, 0, sizeof (sec_attr));
632        memset (&si, 0, sizeof (si));
633        si.cb = sizeof (STARTUPINFO);
634        memset (&pi, 0, sizeof (pi));
635        //hh.exe -mapid 40 "winpt.$lang.chm"
636        
637        _snprintf (path, 2*MAX_PATH, "hh.exe -mapid %d winpt.%s.chm", map_id, gettext_get_langid ());
638        CreateProcess (NULL, path, &sec_attr, &sec_attr, FALSE, 0, NULL, NULL, &si, &pi);
639        CloseHandle (pi.hProcess);
640        CloseHandle (pi.hThread);
641        return 0;
642    }
643                      
644      
645  /* Return TRUE if the current user has admin privileges. */  /* Return TRUE if the current user has admin privileges. */
646  BOOL  BOOL
647  user_is_admin (void)  user_is_admin (void)
648  {  {
649      SID_IDENTIFIER_AUTHORITY SystemSidAuthority = SECURITY_NT_AUTHORITY;      SID_IDENTIFIER_AUTHORITY SystemSidAuthority = {SECURITY_NT_AUTHORITY};
650      HANDLE hd;      HANDLE hd;
651      TOKEN_GROUPS  *ptg = NULL;      TOKEN_GROUPS  *ptg = NULL;
652      DWORD ngtoken;      DWORD ngtoken;
# Line 680  user_is_admin (void) Line 654  user_is_admin (void)
654      BOOL admin = FALSE;      BOOL admin = FALSE;
655      PSID psid = 0;      PSID psid = 0;
656    
     if (GetVersion () & 0x80000000) /* Win9X */  
         return TRUE;  
   
657      if (!OpenThreadToken (GetCurrentThread (), TOKEN_QUERY, FALSE, &hd) &&      if (!OpenThreadToken (GetCurrentThread (), TOKEN_QUERY, FALSE, &hd) &&
658          !OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &hd))          !OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &hd))
659          return FALSE;          return FALSE;
# Line 693  user_is_admin (void) Line 664  user_is_admin (void)
664          if (!ptg)          if (!ptg)
665              return FALSE;              return FALSE;
666    
667          if (!GetTokenInformation (hd, TokenGroups,          if (!GetTokenInformation (hd, TokenGroups, ptg, ngtoken, &ngtoken)) {
                                   ptg, ngtoken, &ngtoken)) {  
668              GlobalFree (ptg);              GlobalFree (ptg);
669              return FALSE;              return FALSE;
670          }          }

Legend:
Removed from v.278  
changed lines
  Added in v.376

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26