00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "vmsAppSettingsStore.h"
00009
00010 #ifdef _DEBUG
00011 #undef THIS_FILE
00012 static char THIS_FILE[]=__FILE__;
00013 #define new DEBUG_NEW
00014 #endif
00015
00016 vmsAppSettingsStore::vmsAppSettingsStore()
00017 {
00018 m_app = AfxGetApp ();
00019 m_bUseRegistry = true;
00020 }
00021
00022 vmsAppSettingsStore::~vmsAppSettingsStore()
00023 {
00024
00025 }
00026
00027 UINT vmsAppSettingsStore::GetProfileInt(LPCSTR pszSection, LPCSTR pszEntry, INT nDefault)
00028 {
00029 if (m_bUseRegistry)
00030 return m_app->GetProfileInt (pszSection, pszEntry, nDefault);
00031
00032 int iValue = nDefault;
00033 m_file.get_Value (pszSection, pszEntry, iValue);
00034 return iValue;
00035 }
00036
00037 BOOL vmsAppSettingsStore::WriteProfileInt(LPCSTR pszSection, LPCSTR pszEntry, int nValue)
00038 {
00039 if (m_bUseRegistry)
00040 return m_app->WriteProfileInt (pszSection, pszEntry, nValue);
00041
00042 m_file.set_Value (pszSection, pszEntry, nValue);
00043 return TRUE;
00044 }
00045
00046 CString vmsAppSettingsStore::GetProfileString(LPCSTR pszSection, LPCSTR pszEntry, LPCSTR pszDefault)
00047 {
00048 if (m_bUseRegistry)
00049 return m_app->GetProfileString (pszSection, pszEntry, pszDefault);
00050
00051 LPCSTR pszValue = pszDefault;
00052 m_file.get_Value (pszSection, pszEntry, pszValue);
00053 return pszValue;
00054 }
00055
00056 BOOL vmsAppSettingsStore::WriteProfileString(LPCSTR pszSection, LPCSTR pszEntry, LPCSTR pszValue)
00057 {
00058 if (m_bUseRegistry)
00059 return m_app->WriteProfileString (pszSection, pszEntry, pszValue);
00060
00061 m_file.set_Value (pszSection, pszEntry, pszValue);
00062 return TRUE;
00063 }
00064
00065 BOOL vmsAppSettingsStore::GetProfileBinary(LPCSTR pszSection, LPCSTR pszEntry, LPBYTE *ppData, UINT *pBytes)
00066 {
00067 if (m_bUseRegistry)
00068 return m_app->GetProfileBinary (pszSection, pszEntry, ppData, pBytes);
00069
00070 LPBYTE pbValue = NULL;
00071 UINT nValueSize = 0;
00072
00073 m_file.get_Value (pszSection, pszEntry, pbValue, nValueSize);
00074
00075 if (pbValue == NULL || nValueSize == 0)
00076 return FALSE;
00077
00078
00079
00080 *ppData = new BYTE [nValueSize];
00081 CopyMemory (*ppData, pbValue, nValueSize);
00082 *pBytes = nValueSize;
00083
00084 return TRUE;
00085 }
00086
00087 BOOL vmsAppSettingsStore::WriteProfileBinary(LPCSTR pszSection, LPCSTR pszEntry, LPBYTE pbData, UINT nBytes)
00088 {
00089 if (m_bUseRegistry)
00090 return m_app->WriteProfileBinary (pszSection, pszEntry, pbData, nBytes);
00091
00092 m_file.set_Value (pszSection, pszEntry, pbData, nBytes);
00093 return TRUE;
00094 }
00095
00096 void vmsAppSettingsStore::LoadSettingsFromFile(LPCSTR pszFile)
00097 {
00098 m_bUseRegistry = false;
00099
00100 HANDLE hFile = CreateFile (pszFile, GENERIC_READ, FILE_SHARE_READ, NULL,
00101 OPEN_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL);
00102 if (hFile == INVALID_HANDLE_VALUE)
00103 return;
00104
00105 try {
00106 m_file.LoadFromFile (hFile);
00107 }catch (...){}
00108
00109 CloseHandle (hFile);
00110 }
00111
00112 void vmsAppSettingsStore::SaveSettingsToFile(LPCSTR pszFile)
00113 {
00114 HANDLE hFile = CreateFile (pszFile, GENERIC_WRITE, 0, NULL,
00115 CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL);
00116 if (hFile == INVALID_HANDLE_VALUE)
00117 return;
00118
00119 try {
00120 m_file.SaveToFile (hFile);
00121 }catch (...){}
00122
00123 CloseHandle (hFile);
00124 }