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 |
* |
* |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU General Public License |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
15 |
*/ |
*/ |
|
|
|
16 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
17 |
#include <config.h> |
#include <config.h> |
18 |
#endif |
#endif |
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); |
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; |
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)); |
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 |
|
|
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 */ |
517 |
GetFileVersionInfo (file, 0, size, buf); |
GetFileVersionInfo (file, 0, size, buf); |
518 |
|
|
519 |
qlen=0; |
qlen=0; |
520 |
VerQueryValue (buf, "\\", &data, &qlen); |
VerQueryValue (buf, (char*)"\\", &data, &qlen); |
521 |
if (!qlen) { |
if (!qlen) { |
522 |
delete [](char*)buf; |
delete [](char*)buf; |
523 |
return -1; |
return -1; |
539 |
|
|
540 |
|
|
541 |
/* Return date in a format which complies with the |
/* Return date in a format which complies with the |
542 |
system locale settings. */ |
locale user settings. */ |
543 |
const char* |
const char* |
544 |
get_locale_date (long tm_t, char *buf, DWORD buflen) |
get_locale_date (long tm_t, char *buf, DWORD buflen) |
545 |
{ |
{ |
546 |
SYSTEMTIME st; |
SYSTEMTIME st; |
547 |
struct tm *ptm; |
struct tm *ptm; |
548 |
|
|
549 |
ptm = localtime (&tm_t); |
ptm = localtime (&tm_t); |
550 |
st.wYear = (WORD)ptm->tm_year; |
memset (&st, 0, sizeof (st)); |
551 |
st.wMonth = (WORD)ptm->tm_mon; |
st.wYear = (WORD)ptm->tm_year+1900; |
552 |
|
st.wMonth = (WORD)ptm->tm_mon+1; |
553 |
st.wDay = (WORD)ptm->tm_mday; |
st.wDay = (WORD)ptm->tm_mday; |
|
st.wYear += 1900; |
|
|
st.wMonth += 1; |
|
554 |
if (!GetDateFormat (LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, |
if (!GetDateFormat (LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, |
555 |
NULL, buf, buflen)) |
NULL, buf, buflen)) |
556 |
return NULL; |
return NULL; |
557 |
return buf; |
return buf; |
558 |
} |
} |
559 |
|
|
560 |
|
/* Return the time in a format which complies with the locale user |
561 |
|
settings. */ |
562 |
|
const char* |
563 |
|
get_locale_time (long tm_t, char *buf, DWORD buflen) |
564 |
|
{ |
565 |
|
SYSTEMTIME st; |
566 |
|
struct tm *ptm; |
567 |
|
|
568 |
|
ptm = localtime (&tm_t); |
569 |
|
memset (&st, 0, sizeof (st)); |
570 |
|
st.wMinute = (WORD)ptm->tm_min; |
571 |
|
st.wHour = (WORD)ptm->tm_hour; |
572 |
|
st.wSecond = (WORD)ptm->tm_sec; |
573 |
|
|
574 |
|
if (!GetTimeFormat (LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT, &st, |
575 |
|
NULL, buf, buflen)) |
576 |
|
return NULL; |
577 |
|
return buf; |
578 |
|
} |
579 |
|
|
580 |
|
|
581 |
|
/* Return a combination of date+time which complies to the |
582 |
|
local user settings. */ |
583 |
|
const char* |
584 |
|
get_locale_timedate (long tm_t, char *buf, DWORD buflen) |
585 |
|
{ |
586 |
|
DWORD nleft = buflen; |
587 |
|
|
588 |
|
if (!get_locale_date (tm_t, buf, buflen)) |
589 |
|
return NULL; |
590 |
|
nleft -= strlen (buf)+1; |
591 |
|
if (nleft < 1) |
592 |
|
return NULL; |
593 |
|
strcat (buf, " "); |
594 |
|
nleft--; |
595 |
|
if (!get_locale_time (tm_t, buf+strlen (buf), nleft)) |
596 |
|
return NULL; |
597 |
|
return buf; |
598 |
|
} |
599 |
|
|
600 |
|
|
601 |
/* Generate a temporary file name by using the users |
/* Generate a temporary file name by using the users |
602 |
temp path and optionally a name @name provided by the caller. |
temp path and optionally a name @name provided by the caller. |
612 |
name = tmp; |
name = tmp; |
613 |
} |
} |
614 |
|
|
|
/* 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 |
|
|
|
|
615 |
if (!GetTempPath (buflen - strlen (name) -2, buf)) { |
if (!GetTempPath (buflen - strlen (name) -2, buf)) { |
616 |
log_debug ("GetTempPath() failed ec=%d\n", (int)GetLastError ()); |
log_debug ("GetTempPath() failed ec=%d\n", (int)GetLastError ()); |
617 |
return -1; |
return -1; |
636 |
void |
void |
637 |
ComboBox_AddString_utf8 (HWND cb, const char *txt) |
ComboBox_AddString_utf8 (HWND cb, const char *txt) |
638 |
{ |
{ |
|
|
|
639 |
char *utf8_txt; |
char *utf8_txt; |
640 |
|
|
641 |
utf8_txt = utf8_to_native (txt); |
utf8_txt = utf8_to_native (txt); |
663 |
return len; |
return len; |
664 |
} |
} |
665 |
|
|
666 |
|
int |
667 |
|
html_help_show (int map_id) |
668 |
|
{ |
669 |
|
STARTUPINFO si; |
670 |
|
PROCESS_INFORMATION pi; |
671 |
|
SECURITY_ATTRIBUTES sec_attr; |
672 |
|
char path[2*MAX_PATH+1]; |
673 |
|
|
674 |
|
memset (&sec_attr, 0, sizeof (sec_attr)); |
675 |
|
memset (&si, 0, sizeof (si)); |
676 |
|
si.cb = sizeof (STARTUPINFO); |
677 |
|
memset (&pi, 0, sizeof (pi)); |
678 |
|
//hh.exe -mapid 40 "winpt.$lang.chm" |
679 |
|
|
680 |
|
_snprintf (path, 2*MAX_PATH, "hh.exe -mapid %d winpt.%s.chm", |
681 |
|
map_id, gettext_get_langid ()); |
682 |
|
CreateProcess (NULL, path, &sec_attr, &sec_attr, |
683 |
|
FALSE, 0, NULL, NULL, &si, &pi); |
684 |
|
CloseHandle (pi.hProcess); |
685 |
|
CloseHandle (pi.hThread); |
686 |
|
return 0; |
687 |
|
} |
688 |
|
|
689 |
|
|
690 |
/* Return TRUE if the current user has admin privileges. */ |
/* Return TRUE if the current user has admin privileges. */ |
691 |
BOOL |
BOOL |
692 |
user_is_admin (void) |
user_is_admin (void) |