TConfigA.cpp
上传用户:haiweijt
上传日期:2018-02-23
资源大小:8195k
文件大小:3k
- #include "TConfigA.h"
- #include <stdio.h>
- #include <windows.h>
- #pragma warning( disable: 4996)
- TConfigA::TConfigA(void)
- {
- }
- TConfigA::~TConfigA(void)
- {
- }
- int CopySafe(char* dest, int size, const char* value)
- {
- int len = strlen(value);
- int max = size-1;
- if (len > max)
- {
- memcpy(dest, value, max);
- dest[max] = ' ';
- return max;
- }
- else
- {
- strcpy(dest, value);
- return len;
- }
- }
- char* SplitePath(const char* FileName)
- {
- static char Path[MAX_PATH];
- char szPath[256];
- char szDrive[256];
- char szFileName[256];
- char szExt[256];
- _splitpath(FileName, szDrive, szPath, szFileName, szExt);
- strcpy(Path, szDrive);
- strcat(Path, szPath);
- return Path;
- }
- char* TConfigA::GetConfigFileName(char* Path, int Size)
- {
- char PathName[256];
- ::GetModuleFileName(NULL, PathName, 256);
- strcpy(PathName, SplitePath(PathName));
- strcat(PathName, "TCSConfig.ini");
- CopySafe(Path, Size, PathName);
- return Path;
- }
- BOOL TConfigA::Open()
- {
- char Path[256];
- GetConfigFileName(Path, 256);
- return Open(Path);
- }
- BOOL TConfigA::Open(const char* FileName)
- {
- strcpy(m_FileName, FileName);
- return TRUE;
- }
- void TConfigA::Close()
- {
- }
- #define SYSTEM_KEY "System"
- void TConfigA::ReadSystemString(LPCTSTR Key, char* Value, int Size)
- {
- ::GetPrivateProfileString(SYSTEM_KEY, Key, "", Value, Size, m_FileName);
-
- }
- void TConfigA::ReadCmd(int index, char* value, int size)
- {
- char buf[32];
- sprintf(buf, "Cmd[%d]",index);
- ::GetPrivateProfileString("CMD",buf,"", value, size, m_FileName);
- }
- void TConfigA::ReadField(int index, char* value, int size)
- {
- char buf[32];
- sprintf(buf, "Field[%d]",index);
- ::GetPrivateProfileString("CMD",buf,"", value, size, m_FileName);
- }
- void TConfigA::ReadCount(char* value,int size)
- {
- ::GetPrivateProfileString("CMD","Count","", value,size, m_FileName);
-
- }
- /*
- void TConfigA::ReadIndex(LPCTSTR App, LPCTSTR Key, int Index, char* value, int size)
- {
- char Buf[32];
- sprintf(Buf, "%s[%d]", Key, Index);
- GetPrivateProfileString(App, Buf, "", value, size, m_FileName);
- }
- void TConfigA::WriteIndex(LPCTSTR App, LPCTSTR Key, int Index, LPCTSTR value)
- {
- char Buf[32];
- sprintf(Buf, "%s[%d]", Key, Index);
- WritePrivateProfileString(App, Buf, value, m_FileName);
- }
- int TConfigA::ReadIndex(LPCTSTR App, LPCTSTR Key, int Index)
- {
- char Buf[32];
- sprintf(Buf, "%s[%d]", Key, Index);
- return GetPrivateProfileInt(App, Buf, 0, m_FileName);
- }
- void TConfigA::WriteIndex(LPCTSTR App, LPCTSTR Key, int Index, int value)
- {
- char Buf[32];
- sprintf(Buf, "%s[%d]", Key, Index);
- WriteInt(App, Buf, value);
- }
- void TConfigA::WriteInt(LPCTSTR App, LPCTSTR Key, int Value)
- {
- char Buf[32];
- sprintf(Buf, "%d", Value);
- WritePrivateProfileString(App, Key, Buf, m_FileName);
- }
- */