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