- Merge aicom-network-fixes up to r36740
[reactos.git] / rosapps / applications / devutils / vgafontedit / opensave.c
1 /*
2 * PROJECT: ReactOS VGA Font Editor
3 * LICENSE: GNU General Public License Version 2.0 or any later version
4 * FILE: devutils/vgafontedit/opensave.c
5 * PURPOSE: Functions for opening and saving files
6 * COPYRIGHT: Copyright 2008 Colin Finck <mail@colinfinck.de>
7 */
8
9 #include "precomp.h"
10
11 static OPENFILENAMEW ofn;
12
13 VOID
14 FileInitialize(IN HWND hwnd)
15 {
16 ZeroMemory( &ofn, sizeof(ofn) );
17 ofn.lStructSize = sizeof(ofn);
18 ofn.hwndOwner = hwnd;
19 ofn.nMaxFile = MAX_PATH;
20 ofn.lpstrDefExt = L"bin";
21 }
22
23 static __inline VOID
24 PrepareFilter(IN PWSTR pszFilter)
25 {
26 // RC strings can't be double-null terminated, so we use | instead to separate the entries.
27 // Convert them back to null characters here.
28 do
29 {
30 if(*pszFilter == '|')
31 *pszFilter = 0;
32 }
33 while(*++pszFilter);
34 }
35
36 BOOL
37 DoOpenFile(OUT PWSTR pszFileName)
38 {
39 BOOL bRet;
40 PWSTR pszFilter;
41
42 if( AllocAndLoadString(&pszFilter, IDS_OPENFILTER) )
43 {
44 PrepareFilter(pszFilter);
45 ofn.lpstrFilter = pszFilter;
46 ofn.lpstrFile = pszFileName;
47 ofn.Flags = OFN_FILEMUSTEXIST;
48
49 bRet = GetOpenFileNameW(&ofn);
50 HeapFree(hProcessHeap, 0, pszFilter);
51
52 return bRet;
53 }
54
55 return FALSE;
56 }
57
58 BOOL
59 DoSaveFile(IN OUT PWSTR pszFileName)
60 {
61 BOOL bRet;
62 PWSTR pszFilter;
63
64 if( AllocAndLoadString(&pszFilter, IDS_SAVEFILTER) )
65 {
66 PrepareFilter(pszFilter);
67 ofn.lpstrFilter = pszFilter;
68 ofn.lpstrFile = pszFileName;
69
70 bRet = GetSaveFileNameW(&ofn);
71 HeapFree(hProcessHeap, 0, pszFilter);
72
73 return bRet;
74 }
75
76 return FALSE;
77 }