forked from svn2github/freearc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GuiEnvironment.cpp
103 lines (86 loc) · 2.67 KB
/
GuiEnvironment.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <stdio.h>
#include <sys/stat.h>
#include <utime.h>
#include <limits.h>
#include <memory.h>
#include "Environment.h"
#include "Compression/Compression.h"
#ifdef FREEARC_WIN
#include <shlobj.h>
static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
if(uMsg == BFFM_INITIALIZED)
PostMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
return 0;
}
// Äàòü ïîëüçîâàòåëþ âûáðàòü êàòàëîã
int BrowseForFolder(TCHAR *prompt, TCHAR *in_filename, TCHAR *out_filename)
{
BROWSEINFO bi;
bi.hwndOwner = GetActiveWindow();
bi.lParam = (LONG)in_filename;
bi.lpszTitle = prompt;
bi.lpfn = BrowseCallbackProc;
bi.pidlRoot = NULL;
bi.pszDisplayName = out_filename;
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI;
LPITEMIDLIST pItemIdList = SHBrowseForFolder(&bi);
int result = 0;
if(pItemIdList != NULL)
{
if (SHGetPathFromIDList(pItemIdList, out_filename))
result = 1;
IMalloc *iMalloc = 0;
if(SUCCEEDED(SHGetMalloc(&iMalloc)))
{
iMalloc->Free(pItemIdList);
iMalloc->Release();
}
}
return result;
}
// Äàòü ïîëüçîâàòåëþ âûáðàòü ôàéë
int BrowseForFile(TCHAR *prompt, TCHAR *filters, TCHAR *in_filename, TCHAR *out_filename)
{
OPENFILENAME ofn;
ZeroMemory (&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = GetActiveWindow();
ofn.lpstrFilter = filters;
ofn.lpstrFile = out_filename;
ofn.nMaxFile = MY_FILENAME_MAX*2;
ofn.lpstrTitle = prompt;
// If "initial filename" looks like "something\." or "something\", it's just initial dir, really
if (in_filename[_tcslen(in_filename)-1] == _T('.') &&
in_filename[_tcslen(in_filename)-2] == _T('\\'))
{
in_filename[_tcslen(in_filename)-1] == _T('\0');
ofn.lpstrInitialDir = in_filename;
_tcscpy (out_filename, _T(""));
}
else if (in_filename[_tcslen(in_filename)-1] == _T('\\'))
{
ofn.lpstrInitialDir = in_filename;
_tcscpy (out_filename, _T(""));
}
else
{
_tcscpy (out_filename, in_filename);
}
return GetOpenFileName(&ofn)? 1 : 0;
}
// Ïðåâðàòèòü âðåìÿ/äàòó ôàéëà â ñòðîêó â ñîîòâåòñòâèè ñ íàñòðîéêàìè locale èëè çàäàííûìè ôîðìàòàìè âðåìåíè è äàòû
void GuiFormatDateTime (time_t t, char *buf, int bufsize, char *date_format, char *time_format)
{
if (t==-1) t=0; // Èíà÷å ïîëó÷èì âûëåò :(
FILETIME ft1, ft2;
UnixTimeToFileTime (t, &ft1);
FileTimeToLocalFileTime (&ft1, &ft2);
SYSTEMTIME datetime;
FileTimeToSystemTime (&ft2, &datetime);
GetDateFormatA(LOCALE_USER_DEFAULT, 0, &datetime, date_format, buf, bufsize);
char *p = str_end(buf);
*p++ = ' ';
GetTimeFormatA(LOCALE_USER_DEFAULT, 0, &datetime, time_format, p, bufsize - (p-buf));
}
#endif // Windows/Unix