forked from LosaDev/ls-2019-source
LosaDev source snapshot 2019
This commit is contained in:
commit
c198676e97
20588 files changed
+8812878
No files matched your search
@@ -0,0 +1,299 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace INILoader
|
||||
{
|
||||
using dicKeyList = Dictionary<String, String>;
|
||||
using dicTitleList = Dictionary<String, Dictionary<String, String>>;
|
||||
public class INILoader
|
||||
{
|
||||
[System.Runtime.InteropServices.DllImport("kernel32")]
|
||||
private static extern long WritePrivateProfileString(String section, String key, String value, String filepath);
|
||||
[System.Runtime.InteropServices.DllImport("kernel32")]
|
||||
private static extern long GetPrivateProfileString(String section, String key, String value, StringBuilder retValue, int size, String filepath);
|
||||
|
||||
public String m_FileName;
|
||||
public String m_szTitle;
|
||||
|
||||
dicTitleList m_TitleList = new dicTitleList();
|
||||
|
||||
bool m_bSaveLog;
|
||||
StreamWriter m_Log;
|
||||
public INILoader()
|
||||
{
|
||||
m_FileName = "";
|
||||
m_szTitle = "";
|
||||
}
|
||||
|
||||
~INILoader()
|
||||
{
|
||||
}
|
||||
|
||||
public INILoader(String szFile, bool save_log)
|
||||
{
|
||||
if (!File.Exists(szFile))
|
||||
return;
|
||||
|
||||
m_bSaveLog = save_log;
|
||||
if( m_bSaveLog )
|
||||
{
|
||||
|
||||
String log_file = Path.GetFileName(szFile);
|
||||
m_Log = new StreamWriter( String.Format( "./{0}.log", log_file ), false, Encoding.Default );
|
||||
}
|
||||
|
||||
m_FileName = szFile;
|
||||
m_szTitle = "";
|
||||
Parsing();
|
||||
}
|
||||
|
||||
public void SetFileName( String szFile )
|
||||
{
|
||||
m_TitleList.Clear();
|
||||
m_FileName = szFile;
|
||||
m_szTitle = "";
|
||||
if (File.Exists(szFile))
|
||||
{
|
||||
Parsing();
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLog(String.Format("ini 파일이 없습니다 : [{0}]", szFile));
|
||||
}
|
||||
}
|
||||
|
||||
public String GetFileName() { return m_FileName; }
|
||||
public void Parsing()
|
||||
{
|
||||
WriteLog("<<< -------------------- INI Load -------------------- >>>");
|
||||
String szLine = String.Empty;
|
||||
String szLastLine = String.Empty;
|
||||
|
||||
StreamReader sr = new StreamReader(m_FileName, Encoding.Default);
|
||||
dicKeyList tempKeyList = new dicKeyList();
|
||||
while (sr.Peek() > -1)
|
||||
{
|
||||
if (szLastLine == String.Empty || szLastLine[0] != '[')
|
||||
{
|
||||
szLine = sr.ReadLine();
|
||||
}
|
||||
else
|
||||
{
|
||||
szLine = szLastLine;
|
||||
szLastLine = String.Empty;
|
||||
}
|
||||
|
||||
szLine = szLine.Replace("\t", "");
|
||||
if (szLine == String.Empty)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (szLine[0] != '[')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
szLastLine = ParseTitle(szLine, ref sr);
|
||||
}
|
||||
|
||||
sr.Close();
|
||||
WriteLog("<<< -------------------- INI Load Complete -------------------- >>>");
|
||||
if( m_bSaveLog )
|
||||
m_Log.Close();
|
||||
}
|
||||
|
||||
private String ParseTitle(String szTitle, ref StreamReader sr)
|
||||
{
|
||||
String szLine = "";
|
||||
dicKeyList tempKeyList = new dicKeyList();
|
||||
while (sr.Peek() > -1)
|
||||
{
|
||||
szLine = sr.ReadLine();
|
||||
szLine = szLine.Replace("\t", "");
|
||||
if (szLine == String.Empty)
|
||||
continue;
|
||||
|
||||
if (szLine[0] == ';')
|
||||
continue;
|
||||
|
||||
if (szLine[0] == '[')
|
||||
break;
|
||||
|
||||
ParseKey(szTitle, szLine, ref tempKeyList);
|
||||
}
|
||||
|
||||
if (tempKeyList.Count > 0)
|
||||
{
|
||||
char[] charSeparators = new char[] { '[', ']' };
|
||||
String[] RetString = szTitle.Split(charSeparators);
|
||||
if( RetString.Length < 3 )
|
||||
WriteLog(String.Format("알수없는 오류 발생 : {0}", szTitle));
|
||||
|
||||
dicKeyList retList;
|
||||
if (!m_TitleList.TryGetValue(RetString[1], out retList))
|
||||
{
|
||||
m_TitleList.Add(RetString[1], tempKeyList);
|
||||
}
|
||||
else
|
||||
{
|
||||
int iCnt = retList.Count;
|
||||
WriteLog(String.Format("중복섹션이 발생했습니다. : {0}", szTitle));
|
||||
}
|
||||
}
|
||||
|
||||
return szLine;
|
||||
}
|
||||
|
||||
private void ParseKey(String szTitle, String szLine, ref dicKeyList KeyList)
|
||||
{
|
||||
char[] charSeparators = new char[] { '=', '\t' };
|
||||
String[] szWord = szLine.Split(charSeparators, 2);
|
||||
if (szWord.Length > 1)
|
||||
{
|
||||
String szKey = szWord[0].Trim();
|
||||
String szValue = szWord[1].Trim();
|
||||
String RetValue;
|
||||
if (!KeyList.TryGetValue(szKey, out RetValue))
|
||||
{
|
||||
KeyList.Add(szKey, szValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
//MessageBox.Show( "이미 있는 키입니다. - "+szKey);
|
||||
WriteLog(String.Format("중복키가 발생했습니다. : {0} {1}", szTitle, szKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTitle(String szSection)
|
||||
{
|
||||
m_szTitle = szSection;
|
||||
}
|
||||
|
||||
public void WriteValue(String key, String value)
|
||||
{
|
||||
if (String.IsNullOrEmpty(m_FileName) || String.IsNullOrEmpty(m_szTitle))
|
||||
return;
|
||||
|
||||
WritePrivateProfileString(m_szTitle, key, String.Format(" {0}", value), m_FileName);
|
||||
}
|
||||
|
||||
public void WriteSection(String section, String key, String value)
|
||||
{
|
||||
WritePrivateProfileString(section, key, value, m_FileName);
|
||||
}
|
||||
|
||||
public String GetValue(String key)
|
||||
{
|
||||
if (String.IsNullOrEmpty(m_szTitle))
|
||||
return String.Empty;
|
||||
|
||||
String retValue = "";
|
||||
dicKeyList KeyList;
|
||||
try
|
||||
{
|
||||
if (m_TitleList.TryGetValue(m_szTitle, out KeyList))
|
||||
{
|
||||
if (KeyList.TryGetValue(key, out retValue))
|
||||
return retValue;
|
||||
}
|
||||
}
|
||||
catch /*(System.Exception e)*/
|
||||
{
|
||||
/*MessageBox.Show(e.Message);*/
|
||||
}
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
public String LoadString(String key, String defVal)
|
||||
{
|
||||
String retVal = GetValue(key);
|
||||
if (String.IsNullOrEmpty(retVal))
|
||||
return defVal;
|
||||
|
||||
return retVal.ToString();
|
||||
}
|
||||
|
||||
public int LoadInt(String key, int defVal)
|
||||
{
|
||||
try
|
||||
{
|
||||
String retVal = GetValue(key);
|
||||
if (String.IsNullOrEmpty(retVal))
|
||||
return defVal;
|
||||
|
||||
return Int32.Parse(retVal);
|
||||
}
|
||||
catch /*(System.Exception e)*/
|
||||
{
|
||||
/*String retVal = GetValue(key);
|
||||
MessageBox.Show( e.Message + "-" + key + retVal );*/
|
||||
}
|
||||
return defVal;
|
||||
}
|
||||
|
||||
public uint LoadUint(String key, uint defVal)
|
||||
{
|
||||
try
|
||||
{
|
||||
String retVal = GetValue(key);
|
||||
if (String.IsNullOrEmpty(retVal))
|
||||
return defVal;
|
||||
|
||||
return uint.Parse(retVal);
|
||||
}
|
||||
catch /*(System.Exception e)*/
|
||||
{
|
||||
/*String retVal = GetValue(key);
|
||||
MessageBox.Show( e.Message + "-" + key + retVal );*/
|
||||
}
|
||||
return defVal;
|
||||
}
|
||||
|
||||
public float LoadFloat(String key, float defVal)
|
||||
{
|
||||
String retVal = GetValue(key);
|
||||
if (String.IsNullOrEmpty(retVal))
|
||||
return defVal;
|
||||
|
||||
return float.Parse(retVal);
|
||||
}
|
||||
|
||||
public bool LoadBool(String key, bool defVal)
|
||||
{
|
||||
try
|
||||
{
|
||||
String retVal = GetValue(key);
|
||||
if (String.IsNullOrEmpty(retVal))
|
||||
return defVal;
|
||||
|
||||
if (int.Parse(retVal) == 0)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
catch /*(System.Exception e)*/
|
||||
{
|
||||
/*String retVal = GetValue(key);
|
||||
MessageBox.Show(e.Message + " - " + key + " = " + retVal);*/
|
||||
}
|
||||
return defVal;
|
||||
}
|
||||
|
||||
private void WriteLog( String log )
|
||||
{
|
||||
if( !m_bSaveLog )
|
||||
return;
|
||||
|
||||
if( m_Log != null )
|
||||
{
|
||||
m_Log.WriteLine( log );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{1631948F-8810-4D6A-97EF-DDD43ABB2210}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>INILoader</RootNamespace>
|
||||
<AssemblyName>INILoader</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="INILoader.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "INILoader", "INILoader.csproj", "{1631948F-8810-4D6A-97EF-DDD43ABB2210}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{1631948F-8810-4D6A-97EF-DDD43ABB2210}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1631948F-8810-4D6A-97EF-DDD43ABB2210}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1631948F-8810-4D6A-97EF-DDD43ABB2210}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1631948F-8810-4D6A-97EF-DDD43ABB2210}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 어셈블리의 일반 정보는 다음 특성 집합을 통해 제어됩니다.
|
||||
// 어셈블리와 관련된 정보를 수정하려면
|
||||
// 이 특성 값을 변경하십시오.
|
||||
[assembly: AssemblyTitle("INILoader")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("INILoader")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
|
||||
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
|
||||
// 해당 형식에 대해 ComVisible 특성을 true로 설정하십시오.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
|
||||
[assembly: Guid("7fd9ac1a-5edb-44f3-9476-5797988a35e7")]
|
||||
|
||||
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
|
||||
//
|
||||
// 주 버전
|
||||
// 부 버전
|
||||
// 빌드 번호
|
||||
// 수정 버전
|
||||
//
|
||||
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 버전이 자동으로
|
||||
// 지정되도록 할 수 있습니다.
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Reference in new issue
Block a user