You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.9 KiB
C

/*
10 years ago
Copyright 2014 Stas'M Corp.
10 years ago
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
10 years ago
http://www.apache.org/licenses/LICENSE-2.0
10 years ago
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "stdafx.h"
#include <Windows.h>
10 years ago
#define MAX_STRING_LEN 255
10 years ago
// Out values struсts
typedef struct _INI_VAR_STRING
{
10 years ago
char Name[MAX_STRING_LEN];
char Value[MAX_STRING_LEN];
} INI_VAR_STRING, *PINI_VAR_STRING;
typedef struct _INI_VAR_DWORD
{
10 years ago
char Name[MAX_STRING_LEN];
#ifndef _WIN64
10 years ago
DWORD ValueDec;
DWORD ValueHex;
#else
10 years ago
DWORD64 ValueDec;
DWORD64 ValueHex;
#endif
10 years ago
} INI_VAR_DWORD, *PINI_VAR_DWORD;
typedef struct _INI_VAR_BYTEARRAY
{
10 years ago
char Name[MAX_STRING_LEN];
10 years ago
BYTE ArraySize;
10 years ago
char Value[MAX_STRING_LEN];
} INI_VAR_BYTEARRAY, *PINI_VAR_BYTEARRAY;
typedef struct _INI_SECTION_VARLIST_ENTRY
{
char String[MAX_STRING_LEN];
} INI_SECTION_VARLIST_ENTRY, *PINI_SECTION_VARLIST_ENTRY;
typedef struct _INI_SECTION_VARLIST
{
DWORD EntriesCount;
[length_is(EntriesCount)] INI_SECTION_VARLIST_ENTRY *NamesEntries;
[length_is(EntriesCount)] INI_SECTION_VARLIST_ENTRY *ValuesEntries;
} INI_SECTION_VARLIST, *PINI_SECTION_VARLIST;
// end
typedef struct _INI_SECTION_VARIABLE
{
10 years ago
char VariableName[MAX_STRING_LEN];
char VariableValue[MAX_STRING_LEN];
} INI_SECTION_VARIABLE, *PINI_SECTION_VARIABLE;
typedef struct _INI_SECTION
{
10 years ago
char SectionName[MAX_STRING_LEN];
DWORD VariablesCount;
[length_is(SectionCount)] INI_SECTION_VARIABLE *Variables;
10 years ago
} INI_SECTION, *PINI_SECTION;
typedef struct _INI_DATA
{
DWORD SectionCount;
[length_is(SectionCount)] INI_SECTION *Section;
} INI_DATA, *PINI_DATA;
class INI_FILE
{
public:
INI_FILE(wchar_t*);
~INI_FILE();
10 years ago
// char block
bool SectionExists(char *SectionName);
10 years ago
bool VariableExists(char *SectionName, char *VariableName);
bool GetVariableInSection(char *SectionName, char *VariableName, INI_VAR_STRING *Variable);
bool GetVariableInSection(char *SectionName, char *VariableName, INI_VAR_DWORD *Variable);
10 years ago
bool GetVariableInSection(char *SectionName, char *VariableName, bool *Variable);
bool GetVariableInSection(char *SectionName, char *VariableName, INI_VAR_BYTEARRAY *Variable);
10 years ago
bool GetSectionVariablesList(char *SectionName, INI_SECTION_VARLIST *VariablesList);
10 years ago
// wchar_t tramps
bool SectionExists(wchar_t *SectionName);
bool VariableExists(wchar_t *SectionName, wchar_t *VariableName);
bool GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName, INI_VAR_STRING *Variable);
bool GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName, INI_VAR_DWORD *Variable);
bool GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName, bool *Variable);
bool GetVariableInSection(wchar_t *SectionName, wchar_t *VariableName, INI_VAR_BYTEARRAY *Variable);
bool GetSectionVariablesList(wchar_t *SectionName, INI_SECTION_VARLIST *VariablesList);
private:
DWORD FileSize; // Ini file size
char *FileRaw; // Ini file raw dump
10 years ago
DWORD FileStringsCount; // String-map length
DWORD *FileStringsMap; // String-map
INI_DATA IniData; // Parsed data
10 years ago
// Common service functions
int StrTrim(char* Str);
// Class service functions
bool CreateStringsMap(); // Create file string-map
bool Parse(); // Parse file to class structures
10 years ago
DWORD GetFileStringFromNum(DWORD StringNumber, char *RetString, DWORD Size); // Get string from string-map
10 years ago
bool IsVariable(char *Str, DWORD StrSize);
bool FillVariable(INI_SECTION_VARIABLE *Variable, char *Str, DWORD StrSize); // Fill INI_SECTION_VARIABLE struct (for Parse)
10 years ago
PINI_SECTION GetSection(char *SectionName);
10 years ago
bool GetVariableInSectionPrivate(char *SectionName, char *VariableName, INI_SECTION_VARIABLE *RetVariable);
};