priprava - v2
This commit is contained in:
@ -0,0 +1,40 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
using namespace System;
|
||||
using namespace System::Reflection;
|
||||
using namespace System::Runtime::CompilerServices;
|
||||
using namespace System::Runtime::InteropServices;
|
||||
using namespace System::Security::Permissions;
|
||||
|
||||
//
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
//
|
||||
[assembly:AssemblyTitleAttribute("MadMilkmanIniSamplesCPP")];
|
||||
[assembly:AssemblyDescriptionAttribute("")];
|
||||
[assembly:AssemblyConfigurationAttribute("")];
|
||||
[assembly:AssemblyCompanyAttribute("")];
|
||||
[assembly:AssemblyProductAttribute("MadMilkmanIniSamplesCPP")];
|
||||
[assembly:AssemblyCopyrightAttribute("Copyright (c) 2015")];
|
||||
[assembly:AssemblyTrademarkAttribute("")];
|
||||
[assembly:AssemblyCultureAttribute("")];
|
||||
|
||||
//
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the value or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
|
||||
[assembly:AssemblyVersionAttribute("1.0.*")];
|
||||
|
||||
[assembly:ComVisible(false)];
|
||||
|
||||
[assembly:CLSCompliantAttribute(true)];
|
||||
|
||||
[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];
|
@ -0,0 +1,463 @@
|
||||
#include "stdafx.h"
|
||||
using namespace System;
|
||||
using namespace System::IO;
|
||||
using namespace System::Text;
|
||||
using namespace System::Collections::Generic;
|
||||
using namespace MadMilkman::Ini;
|
||||
|
||||
void HelloWorld()
|
||||
{
|
||||
// Create new file.
|
||||
IniFile^ file = gcnew IniFile();
|
||||
|
||||
// Add new section.
|
||||
IniSection^ section = file->Sections->Add("Section Name");
|
||||
|
||||
// Add new key and its value.
|
||||
IniKey^ key = section->Keys->Add("Key Name", "Hello World");
|
||||
|
||||
// Read file's specific value.
|
||||
Console::WriteLine(file->Sections["Section Name"]->Keys["Key Name"]->Value);
|
||||
}
|
||||
|
||||
void Create()
|
||||
{
|
||||
// Create new file with default formatting.
|
||||
IniFile^ file = gcnew IniFile(gcnew IniOptions());
|
||||
|
||||
// Add new content.
|
||||
IniSection^ section = gcnew IniSection(file, IniSection::GlobalSectionName);
|
||||
IniKey ^key = gcnew IniKey(file, "Key 1", "Value 1");
|
||||
file->Sections->Add(section);
|
||||
section->Keys->Add(key);
|
||||
|
||||
// Add new content.
|
||||
file->Sections->Add("Section 2")->Keys->Add("Key 2", "Value 2");
|
||||
|
||||
// Add new content.
|
||||
file->Sections->Add(
|
||||
gcnew IniSection(file, "Section 3",
|
||||
gcnew IniKey(file, "Key 3.1", "Value 3.1"),
|
||||
gcnew IniKey(file, "Key 3.2", "Value 3.2")));
|
||||
|
||||
// Add new content.
|
||||
Dictionary<String^, String^>^ collection = gcnew Dictionary<String^, String^>();
|
||||
collection->Add("Key 4.1", "Value 4.1");
|
||||
collection->Add("Key 4.2", "Value 4.2");
|
||||
file->Sections->Add(
|
||||
gcnew IniSection(file, "Section 4", collection));
|
||||
}
|
||||
|
||||
void Load()
|
||||
{
|
||||
IniOptions^ options = gcnew IniOptions();
|
||||
IniFile^ iniFile = gcnew IniFile(options);
|
||||
|
||||
// Load file from path.
|
||||
iniFile->Load("..\\MadMilkman.Ini.Samples.Files\\Load Example.ini");
|
||||
|
||||
// Load file from stream.
|
||||
Stream^ fileStream = File::OpenRead("..\\MadMilkman.Ini.Samples.Files\\Load Example.ini");
|
||||
try { iniFile->Load(fileStream); }
|
||||
finally { delete fileStream; }
|
||||
|
||||
// Load file's content from string.
|
||||
String^ iniContent = "[Section 1]" + Environment::NewLine +
|
||||
"Key 1.1 = Value 1.1" + Environment::NewLine +
|
||||
"Key 1.2 = Value 1.2" + Environment::NewLine +
|
||||
"Key 1.3 = Value 1.3" + Environment::NewLine +
|
||||
"Key 1.4 = Value 1.4";
|
||||
iniFile->Load(gcnew StringReader(iniContent));
|
||||
|
||||
// Read file's content.
|
||||
for each (IniSection^ section in iniFile->Sections)
|
||||
{
|
||||
Console::WriteLine("SECTION: {0}", section->Name);
|
||||
for each (IniKey^ key in section->Keys)
|
||||
{
|
||||
Console::WriteLine("KEY: {0}, VALUE: {1}", key->Name, key->Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Style()
|
||||
{
|
||||
IniFile^ file = gcnew IniFile();
|
||||
file->Sections->Add("Section 1")->Keys->Add("Key 1", "Value 1");
|
||||
file->Sections->Add("Section 2")->Keys->Add("Key 2", "Value 2");
|
||||
file->Sections->Add("Section 3")->Keys->Add("Key 3", "Value 3");
|
||||
|
||||
// Add leading comments.
|
||||
file->Sections[0]->LeadingComment->Text = "Section 1 leading comment.";
|
||||
file->Sections[0]->Keys[0]->LeadingComment->Text = "Key 1 leading comment.";
|
||||
|
||||
// Add trailing comments.
|
||||
file->Sections[1]->TrailingComment->Text = "Section 2 trailing comment->";
|
||||
file->Sections[1]->Keys[0]->TrailingComment->Text = "Key 2 trailing comment->";
|
||||
|
||||
// Add left space, indentation.
|
||||
file->Sections[1]->LeftIndentation = 4;
|
||||
file->Sections[1]->TrailingComment->LeftIndentation = 4;
|
||||
file->Sections[1]->Keys[0]->LeftIndentation = 4;
|
||||
file->Sections[1]->Keys[0]->TrailingComment->LeftIndentation = 4;
|
||||
|
||||
// Add above space, empty lines.
|
||||
file->Sections[2]->TrailingComment->EmptyLinesBefore = 2;
|
||||
}
|
||||
|
||||
void Save()
|
||||
{
|
||||
IniOptions^ options = gcnew IniOptions();
|
||||
IniFile^ iniFile = gcnew IniFile(options);
|
||||
iniFile->Sections->Add(
|
||||
gcnew IniSection(iniFile, "Section 1",
|
||||
gcnew IniKey(iniFile, "Key 1.1", "Value 1.1"),
|
||||
gcnew IniKey(iniFile, "Key 1.2", "Value 1.2"),
|
||||
gcnew IniKey(iniFile, "Key 1.3", "Value 1.3"),
|
||||
gcnew IniKey(iniFile, "Key 1.4", "Value 1.4")));
|
||||
|
||||
// Save file to path.
|
||||
iniFile->Save("..\\MadMilkman.Ini.Samples.Files\\Save Example.ini");
|
||||
|
||||
// Save file to stream.
|
||||
Stream^ fileStream = File::Create("..\\MadMilkman.Ini.Samples.Files\\Save Example.ini");
|
||||
try { iniFile->Save(fileStream); }
|
||||
finally { delete fileStream; }
|
||||
|
||||
// Save file's content to string.
|
||||
StringWriter^ contentWriter = gcnew StringWriter();
|
||||
iniFile->Save(contentWriter);
|
||||
String^ iniContent = contentWriter->ToString();
|
||||
|
||||
Console::WriteLine(iniContent);
|
||||
}
|
||||
|
||||
void Encrypt()
|
||||
{
|
||||
// Enable file's protection by providing an encryption password.
|
||||
IniOptions^ options = gcnew IniOptions();
|
||||
options->EncryptionPassword = "M4dM1lkM4n.1n1";
|
||||
IniFile^ file = gcnew IniFile(options);
|
||||
|
||||
IniSection^ section = file->Sections->Add("User's Account");
|
||||
section->Keys->Add("Username", "John Doe");
|
||||
section->Keys->Add("Password", "P@55\\/\\/0|2D");
|
||||
|
||||
// Save and encrypt the file.
|
||||
file->Save("..\\MadMilkman.Ini.Samples.Files\\Encrypt Example.ini");
|
||||
|
||||
file->Sections->Clear();
|
||||
|
||||
// Load and dencrypt the file.
|
||||
file->Load("..\\MadMilkman.Ini.Samples.Files\\Encrypt Example.ini");
|
||||
|
||||
Console::WriteLine("User Name: {0}", file->Sections[0]->Keys["Username"]->Value);
|
||||
Console::WriteLine("Password: {0}", file->Sections[0]->Keys["Password"]->Value);
|
||||
}
|
||||
|
||||
void Compress()
|
||||
{
|
||||
// Enable file's size reduction.
|
||||
IniOptions^ options = gcnew IniOptions();
|
||||
options->Compression = true;
|
||||
IniFile^ file = gcnew IniFile(options);
|
||||
|
||||
for (int i = 1; i <= 100; i++)
|
||||
{
|
||||
file->Sections->Add("Section " + i)->Keys->Add("Key " + i, "Value " + i);
|
||||
}
|
||||
|
||||
// Save and compress the file.
|
||||
file->Save("..\\MadMilkman.Ini.Samples.Files\\Compress Example.ini");
|
||||
|
||||
file->Sections->Clear();
|
||||
|
||||
// Load and decompress the file.
|
||||
file->Load("..\\MadMilkman.Ini.Samples.Files\\Compress Example.ini");
|
||||
|
||||
Console::WriteLine(file->Sections->Count);
|
||||
}
|
||||
|
||||
void Custom()
|
||||
{
|
||||
IniOptions^ options = gcnew IniOptions();
|
||||
options->CommentStarter = IniCommentStarter::Hash;
|
||||
options->KeyDelimiter = IniKeyDelimiter::Colon;
|
||||
options->KeySpaceAroundDelimiter = true;
|
||||
options->SectionWrapper = IniSectionWrapper::CurlyBrackets;
|
||||
options->Encoding = Encoding::UTF8;
|
||||
IniFile^ file = gcnew IniFile(options);
|
||||
|
||||
// Load file.
|
||||
file->Load("..\\MadMilkman.Ini.Samples.Files\\Custom Example Input.ini");
|
||||
|
||||
// Change first section's fourth key's value.
|
||||
file->Sections[0]->Keys[3]->Value = "NEW VALUE";
|
||||
|
||||
// Save file.
|
||||
file->Save("..\\MadMilkman.Ini.Samples.Files\\Custom Example Output.ini");
|
||||
}
|
||||
|
||||
void Copy()
|
||||
{
|
||||
// Create new file.
|
||||
IniFile^ file = gcnew IniFile();
|
||||
|
||||
// Add new content.
|
||||
IniSection^ section = file->Sections->Add("Section");
|
||||
IniKey^ key = section->Keys->Add("Key");
|
||||
|
||||
// Add duplicate section.
|
||||
file->Sections->Add(section->Copy());
|
||||
|
||||
// Add duplicate key.
|
||||
section->Keys->Add(key->Copy());
|
||||
|
||||
// Create new file.
|
||||
IniFile^ newFile = gcnew IniFile(gcnew IniOptions());
|
||||
|
||||
// Import first file's section to second file.
|
||||
newFile->Sections->Add(section->Copy(newFile));
|
||||
}
|
||||
|
||||
void Parse()
|
||||
{
|
||||
IniFile^ file = gcnew IniFile();
|
||||
String^ content = "[Player]" + Environment::NewLine +
|
||||
"Full Name = John Doe" + Environment::NewLine +
|
||||
"Birthday = 12/31/1999" + Environment::NewLine +
|
||||
"Married = Yes" + Environment::NewLine +
|
||||
"Score = 9999999" + Environment::NewLine +
|
||||
"Game Time = 00:59:59";
|
||||
file->Load(gcnew StringReader(content));
|
||||
|
||||
// Map 'yes' value as 'true' boolean.
|
||||
file->ValueMappings->Add("yes", true);
|
||||
// Map 'no' value as 'false' boolean.
|
||||
file->ValueMappings->Add("no", false);
|
||||
|
||||
IniSection^ playerSection = file->Sections["Player"];
|
||||
|
||||
// Retrieve player's name.
|
||||
String^ playerName = playerSection->Keys["Full Name"]->Value;
|
||||
|
||||
// Retrieve player's birthday as DateTime.
|
||||
DateTime playerBirthday;
|
||||
playerSection->Keys["Birthday"]->TryParseValue(playerBirthday);
|
||||
|
||||
// Retrieve player's marital status as bool.
|
||||
// TryParseValue succeeds due to the mapping of 'yes' value to 'true' boolean.
|
||||
bool playerMarried;
|
||||
playerSection->Keys["Married"]->TryParseValue(playerMarried);
|
||||
|
||||
// Retrieve player's score as long.
|
||||
long playerScore;
|
||||
playerSection->Keys["Score"]->TryParseValue(playerScore);
|
||||
|
||||
// Retrieve player's game time as TimeSpan.
|
||||
TimeSpan playerGameTime;
|
||||
playerSection->Keys["Game Time"]->TryParseValue(playerGameTime);
|
||||
}
|
||||
|
||||
void BindInternal()
|
||||
{
|
||||
IniFile^ file = gcnew IniFile();
|
||||
String^ content = "[Machine Settings]" + Environment::NewLine +
|
||||
"Program Files = C:\\Program Files" + Environment::NewLine +
|
||||
"[Application Settings]" + Environment::NewLine +
|
||||
"Name = Example App" + Environment::NewLine +
|
||||
"Version = 1.0" + Environment::NewLine +
|
||||
"Full Name = @{Name} v@{Version}" + Environment::NewLine +
|
||||
"Executable Path = @{Machine Settings|Program Files}\\@{Name}.exe";
|
||||
file->Load(gcnew StringReader(content));
|
||||
|
||||
// Bind placeholders with file's content, internal information.
|
||||
file->ValueBinding->Bind();
|
||||
|
||||
// Retrieve application's full name, value is 'Example App v1.0'.
|
||||
String^ appFullName = file->Sections["Application Settings"]->Keys["Full Name"]->Value;
|
||||
|
||||
// Retrieve application's executable path, value is 'C:\\Program Files\\Example App.exe'.
|
||||
String^ appExePath = file->Sections["Application Settings"]->Keys["Executable Path"]->Value;
|
||||
}
|
||||
|
||||
void BindExternal()
|
||||
{
|
||||
IniFile^ file = gcnew IniFile();
|
||||
String^ content = "[User's Settings]" + Environment::NewLine +
|
||||
"Nickname = @{User Alias}" + Environment::NewLine +
|
||||
"Full Name = @{User Name} @{User Surname}" + Environment::NewLine +
|
||||
"Profile Page = @{Homepage}/Profiles/@{User Alias}";
|
||||
file->Load(gcnew StringReader(content));
|
||||
|
||||
// Bind placeholders with user's data, external information.
|
||||
Dictionary<String^, String^>^ userData = gcnew Dictionary<String^, String^>();
|
||||
userData->Add("User Alias", "Johny");
|
||||
userData->Add("User Name", "John");
|
||||
userData->Add("User Surname", "Doe");
|
||||
file->ValueBinding->Bind(userData);
|
||||
|
||||
// Bind 'Homepage' placeholder with 'www.example.com' value.
|
||||
file->ValueBinding->Bind(
|
||||
KeyValuePair<String^, String^>("Homepage", "www.example.com"));
|
||||
|
||||
// Retrieve user's full name, value is 'John Doe'.
|
||||
String^ userFullName = file->Sections["User's Settings"]->Keys["Full Name"]->Value;
|
||||
|
||||
// Retrieve user's profile page, value is 'www.example.com/Profiles/Johny'.
|
||||
String^ userProfilePage = file->Sections["User's Settings"]->Keys["Profile Page"]->Value;
|
||||
}
|
||||
|
||||
private ref class BindingCustomizationSample {
|
||||
public:
|
||||
void BindCustomize()
|
||||
{
|
||||
IniFile^ file = gcnew IniFile();
|
||||
String^ content = "[Player]" + Environment::NewLine +
|
||||
"Name = @{Name}" + Environment::NewLine +
|
||||
"Surname = @{Surname}" + Environment::NewLine +
|
||||
"Adult = @{Age}" + Environment::NewLine +
|
||||
"Medal = @{Rank}";
|
||||
file->Load(gcnew StringReader(content));
|
||||
|
||||
// Customize binding operation.
|
||||
file->ValueBinding->Binding += gcnew EventHandler<IniValueBindingEventArgs^>(this, &BindingCustomizationSample::CustomEventHandler);
|
||||
|
||||
// Execute binding operation.
|
||||
Dictionary<String^, String^>^ dataSource = gcnew Dictionary<String^, String^>();
|
||||
dataSource->Add("Name", "John");
|
||||
dataSource->Add("Age", "20");
|
||||
dataSource->Add("Rank", "1");
|
||||
file->ValueBinding->Bind(dataSource);
|
||||
}
|
||||
|
||||
void CustomEventHandler(Object^ sender, IniValueBindingEventArgs^ e)
|
||||
{
|
||||
if (!e->IsValueFound)
|
||||
{
|
||||
e->Value = "UNKNOWN";
|
||||
return;
|
||||
}
|
||||
if (e->PlaceholderKey->Name->Equals("Adult") && e->PlaceholderName->Equals("Age"))
|
||||
{
|
||||
int age;
|
||||
if (int::TryParse(e->Value, age))
|
||||
{
|
||||
e->Value = (age >= 18) ? "YES" : "NO";
|
||||
}
|
||||
else
|
||||
{
|
||||
e->Value = "UNKNOWN";
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (e->PlaceholderKey->Name->Equals("Medal") && e->PlaceholderName->Equals("Rank"))
|
||||
{
|
||||
int rank;
|
||||
if (int::TryParse(e->Value, rank))
|
||||
{
|
||||
switch (rank)
|
||||
{
|
||||
case 1:
|
||||
e->Value = "GOLD";
|
||||
break;
|
||||
case 2:
|
||||
e->Value = "SILVER";
|
||||
break;
|
||||
case 3:
|
||||
e->Value = "BRONCE";
|
||||
break;
|
||||
default:
|
||||
e->Value = "NONE";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
e->Value = "UNKNOWN";
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Custom type used for serialization sample.
|
||||
private ref class GameCharacter
|
||||
{
|
||||
public:
|
||||
property String^ Name;
|
||||
|
||||
// Serialize this property as a key with "Sword" name.
|
||||
[IniSerialization("Sword")]
|
||||
property double Attack;
|
||||
|
||||
// Serialize this property as a key with "Shield" name.
|
||||
[IniSerialization("Shield")]
|
||||
property double Defence;
|
||||
|
||||
// Ignore serializing this property.
|
||||
[IniSerialization(true)]
|
||||
property double Health;
|
||||
|
||||
GameCharacter()
|
||||
{
|
||||
this->Health = 100;
|
||||
}
|
||||
};
|
||||
|
||||
void Serialize()
|
||||
{
|
||||
IniFile^ file = gcnew IniFile();
|
||||
IniSection^ section = file->Sections->Add("User's Character");
|
||||
|
||||
GameCharacter^ character = gcnew GameCharacter();
|
||||
character->Name = "John";
|
||||
character->Attack = 5.5;
|
||||
character->Defence = 1;
|
||||
character->Health = 75;
|
||||
|
||||
// Serialize GameCharacter object into section's keys.
|
||||
section->Serialize(character);
|
||||
|
||||
// Deserialize section into GameCharacter object.
|
||||
GameCharacter^ savedCharacter = section->Deserialize<GameCharacter^>();
|
||||
|
||||
Console::WriteLine(section->Keys["Name"]->Value);
|
||||
Console::WriteLine(savedCharacter->Name);
|
||||
Console::WriteLine(section->Keys["Sword"]->Value);
|
||||
Console::WriteLine(savedCharacter->Attack);
|
||||
Console::WriteLine(section->Keys["Shield"]->Value);
|
||||
Console::WriteLine(savedCharacter->Defence);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
HelloWorld();
|
||||
|
||||
Create();
|
||||
|
||||
Load();
|
||||
|
||||
Style();
|
||||
|
||||
Save();
|
||||
|
||||
Encrypt();
|
||||
|
||||
Compress();
|
||||
|
||||
Custom();
|
||||
|
||||
Copy();
|
||||
|
||||
Parse();
|
||||
|
||||
BindInternal();
|
||||
|
||||
BindExternal();
|
||||
|
||||
BindingCustomizationSample^ sample = gcnew BindingCustomizationSample();
|
||||
sample->BindCustomize();
|
||||
|
||||
Serialize();
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{097C11FE-8D4B-48D8-884E-0747454E43DB}</ProjectGuid>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<Keyword>ManagedCProj</Keyword>
|
||||
<RootNamespace>MadMilkmanIniSamplesCPP</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<CLRSupport>true</CLRSupport>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<CLRSupport>true</CLRSupport>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies />
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies />
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="AssemblyInfo.cpp" />
|
||||
<ClCompile Include="IniSamples.cpp" />
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\MadMilkman.Ini\MadMilkman.Ini.csproj">
|
||||
<Project>{bef9735d-c3cc-41e6-aac6-18c5985d3107}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="AssemblyInfo.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="IniSamples.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -0,0 +1,7 @@
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// MadMilkman.Ini.Samples.CPP.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
// TODO: reference additional headers your program requires here
|
@ -0,0 +1,456 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using MadMilkman.Ini;
|
||||
|
||||
namespace MadMilkman.Ini.Samples.CS
|
||||
{
|
||||
class IniSamples
|
||||
{
|
||||
private static void HelloWorld()
|
||||
{
|
||||
// Create new file.
|
||||
IniFile file = new IniFile();
|
||||
|
||||
// Add new section.
|
||||
IniSection section = file.Sections.Add("Section Name");
|
||||
|
||||
// Add new key and its value.
|
||||
IniKey key = section.Keys.Add("Key Name", "Hello World");
|
||||
|
||||
// Read file's specific value.
|
||||
Console.WriteLine(file.Sections["Section Name"].Keys["Key Name"].Value);
|
||||
}
|
||||
|
||||
private static void Create()
|
||||
{
|
||||
// Create new file with a default formatting.
|
||||
IniFile file = new IniFile(new IniOptions());
|
||||
|
||||
// Add new content.
|
||||
IniSection section = new IniSection(file, IniSection.GlobalSectionName);
|
||||
IniKey key = new IniKey(file, "Key 1", "Value 1");
|
||||
file.Sections.Add(section);
|
||||
section.Keys.Add(key);
|
||||
|
||||
// Add new content.
|
||||
file.Sections.Add("Section 2").Keys.Add("Key 2", "Value 2");
|
||||
|
||||
// Add new content.
|
||||
file.Sections.Add(
|
||||
new IniSection(file, "Section 3",
|
||||
new IniKey(file, "Key 3.1", "Value 3.1"),
|
||||
new IniKey(file, "Key 3.2", "Value 3.2")));
|
||||
|
||||
// Add new content.
|
||||
file.Sections.Add(
|
||||
new IniSection(file, "Section 4",
|
||||
new Dictionary<string, string>()
|
||||
{
|
||||
{"Key 4.1", "Value 4.1"},
|
||||
{"Key 4.2", "Value 4.2"}
|
||||
}));
|
||||
}
|
||||
|
||||
private static void Load()
|
||||
{
|
||||
IniOptions options = new IniOptions();
|
||||
IniFile iniFile = new IniFile(options);
|
||||
|
||||
// Load file from path.
|
||||
iniFile.Load(@"..\..\..\MadMilkman.Ini.Samples.Files\Load Example.ini");
|
||||
|
||||
// Load file from stream.
|
||||
using (Stream stream = File.OpenRead(@"..\..\..\MadMilkman.Ini.Samples.Files\Load Example.ini"))
|
||||
iniFile.Load(stream);
|
||||
|
||||
// Load file's content from string.
|
||||
string iniContent = "[Section 1]" + Environment.NewLine +
|
||||
"Key 1.1 = Value 1.1" + Environment.NewLine +
|
||||
"Key 1.2 = Value 1.2" + Environment.NewLine +
|
||||
"Key 1.3 = Value 1.3" + Environment.NewLine +
|
||||
"Key 1.4 = Value 1.4";
|
||||
iniFile.Load(new StringReader(iniContent));
|
||||
|
||||
// Read file's content.
|
||||
foreach (var section in iniFile.Sections)
|
||||
{
|
||||
Console.WriteLine("SECTION: {0}", section.Name);
|
||||
foreach (var key in section.Keys)
|
||||
Console.WriteLine("KEY: {0}, VALUE: {1}", key.Name, key.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Style()
|
||||
{
|
||||
IniFile file = new IniFile();
|
||||
file.Sections.Add("Section 1").Keys.Add("Key 1", "Value 1");
|
||||
file.Sections.Add("Section 2").Keys.Add("Key 2", "Value 2");
|
||||
file.Sections.Add("Section 3").Keys.Add("Key 3", "Value 3");
|
||||
|
||||
// Add leading comments.
|
||||
file.Sections[0].LeadingComment.Text = "Section 1 leading comment.";
|
||||
file.Sections[0].Keys[0].LeadingComment.Text = "Key 1 leading comment.";
|
||||
|
||||
// Add trailing comments.
|
||||
file.Sections[1].TrailingComment.Text = "Section 2 trailing comment.";
|
||||
file.Sections[1].Keys[0].TrailingComment.Text = "Key 2 trailing comment.";
|
||||
|
||||
// Add left space, indentation.
|
||||
file.Sections[1].LeftIndentation = 4;
|
||||
file.Sections[1].TrailingComment.LeftIndentation = 4;
|
||||
file.Sections[1].Keys[0].LeftIndentation = 4;
|
||||
file.Sections[1].Keys[0].TrailingComment.LeftIndentation = 4;
|
||||
|
||||
// Add above space, empty lines.
|
||||
file.Sections[2].TrailingComment.EmptyLinesBefore = 2;
|
||||
}
|
||||
|
||||
private static void Save()
|
||||
{
|
||||
IniOptions options = new IniOptions();
|
||||
IniFile iniFile = new IniFile(options);
|
||||
iniFile.Sections.Add(
|
||||
new IniSection(iniFile, "Section 1",
|
||||
new IniKey(iniFile, "Key 1.1", "Value 1.1"),
|
||||
new IniKey(iniFile, "Key 1.2", "Value 1.2"),
|
||||
new IniKey(iniFile, "Key 1.3", "Value 1.3"),
|
||||
new IniKey(iniFile, "Key 1.4", "Value 1.4")));
|
||||
|
||||
// Save file to path.
|
||||
iniFile.Save(@"..\..\..\MadMilkman.Ini.Samples.Files\Save Example.ini");
|
||||
|
||||
// Save file to stream.
|
||||
using (Stream stream = File.Create(@"..\..\..\MadMilkman.Ini.Samples.Files\Save Example.ini"))
|
||||
iniFile.Save(stream);
|
||||
|
||||
// Save file's content to string.
|
||||
StringWriter contentWriter = new StringWriter();
|
||||
iniFile.Save(contentWriter);
|
||||
string iniContent = contentWriter.ToString();
|
||||
|
||||
Console.WriteLine(iniContent);
|
||||
}
|
||||
|
||||
private static void Encrypt()
|
||||
{
|
||||
// Enable file's protection by providing an encryption password.
|
||||
IniOptions options = new IniOptions() { EncryptionPassword = "M4dM1lkM4n.1n1" };
|
||||
IniFile file = new IniFile(options);
|
||||
|
||||
IniSection section = file.Sections.Add("User's Account");
|
||||
section.Keys.Add("Username", "John Doe");
|
||||
section.Keys.Add("Password", @"P@55\/\/0|2D");
|
||||
|
||||
// Save and encrypt the file.
|
||||
file.Save(@"..\..\..\MadMilkman.Ini.Samples.Files\Encrypt Example.ini");
|
||||
|
||||
file.Sections.Clear();
|
||||
|
||||
// Load and dencrypt the file.
|
||||
file.Load(@"..\..\..\MadMilkman.Ini.Samples.Files\Encrypt Example.ini");
|
||||
|
||||
Console.WriteLine("User Name: {0}", file.Sections[0].Keys["Username"].Value);
|
||||
Console.WriteLine("Password: {0}", file.Sections[0].Keys["Password"].Value);
|
||||
}
|
||||
|
||||
private static void Compress()
|
||||
{
|
||||
// Enable file's size reduction.
|
||||
IniOptions options = new IniOptions() { Compression = true };
|
||||
IniFile file = new IniFile(options);
|
||||
|
||||
for (int i = 1; i <= 100; i++)
|
||||
file.Sections.Add("Section " + i).Keys.Add("Key " + i, "Value " + i);
|
||||
|
||||
// Save and compress the file.
|
||||
file.Save(@"..\..\..\MadMilkman.Ini.Samples.Files\Compress Example.ini");
|
||||
|
||||
file.Sections.Clear();
|
||||
|
||||
// Load and decompress the file.
|
||||
file.Load(@"..\..\..\MadMilkman.Ini.Samples.Files\Compress Example.ini");
|
||||
|
||||
Console.WriteLine(file.Sections.Count);
|
||||
}
|
||||
|
||||
private static void Custom()
|
||||
{
|
||||
// Create new file with custom formatting.
|
||||
IniFile file = new IniFile(
|
||||
new IniOptions()
|
||||
{
|
||||
CommentStarter = IniCommentStarter.Hash,
|
||||
KeyDelimiter = IniKeyDelimiter.Colon,
|
||||
KeySpaceAroundDelimiter = true,
|
||||
SectionWrapper = IniSectionWrapper.CurlyBrackets,
|
||||
Encoding = Encoding.UTF8
|
||||
});
|
||||
|
||||
// Load file.
|
||||
file.Load(@"..\..\..\MadMilkman.Ini.Samples.Files\Custom Example Input.ini");
|
||||
|
||||
// Change first section's fourth key's value.
|
||||
file.Sections[0].Keys[3].Value = "NEW VALUE";
|
||||
|
||||
// Save file.
|
||||
file.Save(@"..\..\..\MadMilkman.Ini.Samples.Files\Custom Example Output.ini");
|
||||
}
|
||||
|
||||
private static void Copy()
|
||||
{
|
||||
// Create new file.
|
||||
IniFile file = new IniFile();
|
||||
|
||||
// Add new content.
|
||||
IniSection section = file.Sections.Add("Section");
|
||||
IniKey key = section.Keys.Add("Key");
|
||||
|
||||
// Add duplicate section.
|
||||
file.Sections.Add(section.Copy());
|
||||
|
||||
// Add duplicate key.
|
||||
section.Keys.Add(key.Copy());
|
||||
|
||||
// Create new file.
|
||||
IniFile newFile = new IniFile(new IniOptions());
|
||||
|
||||
// Import first file's section to second file.
|
||||
newFile.Sections.Add(section.Copy(newFile));
|
||||
}
|
||||
|
||||
private static void Parse()
|
||||
{
|
||||
IniFile file = new IniFile();
|
||||
string content = "[Player]" + Environment.NewLine +
|
||||
"Full Name = John Doe" + Environment.NewLine +
|
||||
"Birthday = 12/31/1999" + Environment.NewLine +
|
||||
"Married = Yes" + Environment.NewLine +
|
||||
"Score = 9999999" + Environment.NewLine +
|
||||
"Game Time = 00:59:59";
|
||||
file.Load(new StringReader(content));
|
||||
|
||||
// Map 'yes' value as 'true' boolean.
|
||||
file.ValueMappings.Add("yes", true);
|
||||
// Map 'no' value as 'false' boolean.
|
||||
file.ValueMappings.Add("no", false);
|
||||
|
||||
IniSection playerSection = file.Sections["Player"];
|
||||
|
||||
// Retrieve player's name.
|
||||
string playerName = playerSection.Keys["Full Name"].Value;
|
||||
|
||||
// Retrieve player's birthday as DateTime.
|
||||
DateTime playerBirthday;
|
||||
playerSection.Keys["Birthday"].TryParseValue(out playerBirthday);
|
||||
|
||||
// Retrieve player's marital status as bool.
|
||||
// TryParseValue succeeds due to the mapping of 'yes' value to 'true' boolean.
|
||||
bool playerMarried;
|
||||
playerSection.Keys["Married"].TryParseValue(out playerMarried);
|
||||
|
||||
// Retrieve player's score as long.
|
||||
long playerScore;
|
||||
playerSection.Keys["Score"].TryParseValue(out playerScore);
|
||||
|
||||
// Retrieve player's game time as TimeSpan.
|
||||
TimeSpan playerGameTime;
|
||||
playerSection.Keys["Game Time"].TryParseValue(out playerGameTime);
|
||||
}
|
||||
|
||||
private static void BindInternal()
|
||||
{
|
||||
IniFile file = new IniFile();
|
||||
string content = "[Machine Settings]" + Environment.NewLine +
|
||||
"Program Files = C:\\Program Files" + Environment.NewLine +
|
||||
"[Application Settings]" + Environment.NewLine +
|
||||
"Name = Example App" + Environment.NewLine +
|
||||
"Version = 1.0" + Environment.NewLine +
|
||||
"Full Name = @{Name} v@{Version}" + Environment.NewLine +
|
||||
"Executable Path = @{Machine Settings|Program Files}\\@{Name}.exe";
|
||||
file.Load(new StringReader(content));
|
||||
|
||||
// Bind placeholders with file's content, internal information.
|
||||
file.ValueBinding.Bind();
|
||||
|
||||
// Retrieve application's full name, value is 'Example App v1.0'.
|
||||
string appFullName = file.Sections["Application Settings"].Keys["Full Name"].Value;
|
||||
|
||||
// Retrieve application's executable path, value is 'C:\\Program Files\\Example App.exe'.
|
||||
string appExePath = file.Sections["Application Settings"].Keys["Executable Path"].Value;
|
||||
}
|
||||
|
||||
private static void BindExternal()
|
||||
{
|
||||
IniFile file = new IniFile();
|
||||
string content = "[User's Settings]" + Environment.NewLine +
|
||||
"Nickname = @{User Alias}" + Environment.NewLine +
|
||||
"Full Name = @{User Name} @{User Surname}" + Environment.NewLine +
|
||||
"Profile Page = @{Homepage}/Profiles/@{User Alias}";
|
||||
file.Load(new StringReader(content));
|
||||
|
||||
// Bind placeholders with user's data, external information.
|
||||
file.ValueBinding.Bind(
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
{"User Alias", "Johny"},
|
||||
{"User Name", "John"},
|
||||
{"User Surname", "Doe"}
|
||||
});
|
||||
|
||||
// Bind 'Homepage' placeholder with 'www.example.com' value.
|
||||
file.ValueBinding.Bind(
|
||||
new KeyValuePair<string, string>("Homepage", "www.example.com"));
|
||||
|
||||
// Retrieve user's full name, value is 'John Doe'.
|
||||
string userFullName = file.Sections["User's Settings"].Keys["Full Name"].Value;
|
||||
|
||||
// Retrieve user's profile page, value is 'www.example.com/Profiles/Johny'.
|
||||
string userProfilePage = file.Sections["User's Settings"].Keys["Profile Page"].Value;
|
||||
}
|
||||
|
||||
private static void BindCustomize()
|
||||
{
|
||||
IniFile file = new IniFile();
|
||||
string content = "[Player]" + Environment.NewLine +
|
||||
"Name = @{Name}" + Environment.NewLine +
|
||||
"Surname = @{Surname}" + Environment.NewLine +
|
||||
"Adult = @{Age}" + Environment.NewLine +
|
||||
"Medal = @{Rank}";
|
||||
file.Load(new StringReader(content));
|
||||
|
||||
// Customize binding operation.
|
||||
file.ValueBinding.Binding += (sender, e) =>
|
||||
{
|
||||
// Set placeholders that do not have a value in data source to 'UNKNOWN'.
|
||||
if (!e.IsValueFound)
|
||||
{
|
||||
e.Value = "UNKNOWN";
|
||||
return;
|
||||
}
|
||||
|
||||
// Set 'Age' placeholder inside 'Adult' key to an appropriate value.
|
||||
if (e.PlaceholderKey.Name.Equals("Adult") && e.PlaceholderName.Equals("Age"))
|
||||
{
|
||||
int age;
|
||||
if (int.TryParse(e.Value, out age))
|
||||
e.Value = (age >= 18) ? "YES" : "NO";
|
||||
else
|
||||
e.Value = "UNKNOWN";
|
||||
return;
|
||||
}
|
||||
|
||||
// Set 'Rank' placeholder inside 'Medal' key to an appropriate value.
|
||||
if (e.PlaceholderKey.Name.Equals("Medal") && e.PlaceholderName.Equals("Rank"))
|
||||
{
|
||||
int rank;
|
||||
if (int.TryParse(e.Value, out rank))
|
||||
switch (rank)
|
||||
{
|
||||
case 1:
|
||||
e.Value = "GOLD";
|
||||
break;
|
||||
case 2:
|
||||
e.Value = "SILVER";
|
||||
break;
|
||||
case 3:
|
||||
e.Value = "BRONCE";
|
||||
break;
|
||||
default:
|
||||
e.Value = "NONE";
|
||||
break;
|
||||
}
|
||||
else
|
||||
e.Value = "UNKNOWN";
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Execute binding operation.
|
||||
file.ValueBinding.Bind(
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
{"Name", "John"},
|
||||
{"Age", "20"},
|
||||
{"Rank", "1"}
|
||||
});
|
||||
}
|
||||
|
||||
// Custom type used for serialization sample.
|
||||
private class GameCharacter
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
// Serialize this property as a key with "Sword" name.
|
||||
[IniSerialization("Sword")]
|
||||
public double Attack { get; set; }
|
||||
|
||||
// Serialize this property as a key with "Shield" name.
|
||||
[IniSerialization("Shield")]
|
||||
public double Defence { get; set; }
|
||||
|
||||
// Ignore serializing this property.
|
||||
[IniSerialization(true)]
|
||||
public double Health { get; set; }
|
||||
|
||||
public GameCharacter() { this.Health = 100; }
|
||||
}
|
||||
|
||||
private static void Serialize()
|
||||
{
|
||||
IniFile file = new IniFile();
|
||||
IniSection section = file.Sections.Add("User's Character");
|
||||
|
||||
GameCharacter character = new GameCharacter();
|
||||
character.Name = "John";
|
||||
character.Attack = 5.5;
|
||||
character.Defence = 1;
|
||||
character.Health = 75;
|
||||
|
||||
// Serialize GameCharacter object into section's keys.
|
||||
section.Serialize(character);
|
||||
|
||||
// Deserialize section into GameCharacter object.
|
||||
GameCharacter savedCharacter = section.Deserialize<GameCharacter>();
|
||||
|
||||
Console.WriteLine(section.Keys["Name"].Value);
|
||||
Console.WriteLine(savedCharacter.Name);
|
||||
Console.WriteLine(section.Keys["Sword"].Value);
|
||||
Console.WriteLine(savedCharacter.Attack);
|
||||
Console.WriteLine(section.Keys["Shield"].Value);
|
||||
Console.WriteLine(savedCharacter.Defence);
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
HelloWorld();
|
||||
|
||||
Create();
|
||||
|
||||
Load();
|
||||
|
||||
Style();
|
||||
|
||||
Save();
|
||||
|
||||
Encrypt();
|
||||
|
||||
Compress();
|
||||
|
||||
Custom();
|
||||
|
||||
Copy();
|
||||
|
||||
Parse();
|
||||
|
||||
BindInternal();
|
||||
|
||||
BindExternal();
|
||||
|
||||
BindCustomize();
|
||||
|
||||
Serialize();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{67F5741B-F6B2-4A4B-8E83-E0FD108086B1}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>MadMilkman.Ini.Samples.CS</RootNamespace>
|
||||
<AssemblyName>MadMilkman.Ini.Samples.CS</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="IniSamples.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\MadMilkman.Ini\MadMilkman.Ini.csproj">
|
||||
<Project>{bef9735d-c3cc-41e6-aac6-18c5985d3107}</Project>
|
||||
<Name>MadMilkman.Ini</Name>
|
||||
</ProjectReference>
|
||||
</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,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("MadMilkman.Ini.Samples.CS")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("MadMilkman.Ini.Samples.CS")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("b1e20845-bdae-4fbe-842c-42d4ee655565")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
@ -0,0 +1 @@
|
||||
BAwAAB+LCAAAAAAABABV1j2OUDkQReEciT30EtpVrr+AFRAikaAJRqMORkKQQMDuIfAx98Unep/87Pvl09t/P/7//u1l/fP+3ce3Xy/rw+d/v/58e1nv332h2Wl2mknz0/w0l7ZP26dtaXFanBbS8rQ8LaXVaXVaSevT+rSWNqfNaSNtvfLxr3z9q+Zrc3FUZ8Gz8FkKtBBaEC01WiAtlJYyLZwWUEulFlQLq6VYC60F11KvBdhCbCnZwmyBtlTNUDPUTNUMNUPNHmfqHqp7qlTNUDPUTNUMNUPNVM1QM9RM1Qw1Q81UzVAz1EzVDDVDzVTNUDPUTNUcNUfNVc1Rc9Rc1Rw1R80fP+P9G+/vqGqOmqPmquaoOWquao6ao+aq5qg5aq5qjpqj5qrmqDlqrmobtY3aVrWN2kZtq9pGbaO2VW2jtlHbj1vsXmP3HlO1jdpGbavaRm2jtlVto7ZR26q2UduobVXbqG3UtqoFaoFaqFqgFqiFqgVqgVqoWqAWqIWqBWqBWjyu/3v/3wdA1QK1QC1ULVAL1ELVArVALVQtUAvUQtUStUQtVS1RS9RS1RK1RC1VLVFL1FLVErVELVUtUUvU8vFu3ofzvpyqlqglaqlqiVqilqqWqCVqqWqFWqFWqlaoFWqlaoVaoVaqVqgVaqVqhVqhVqpWqBVqpWqFWqFWj8FxF8edHKpWqBVqpWqFWqFWqtaoNWqtao1ao9aq1qg1aq1qjVqj1qrWqDVqrWqNWqPWqtaoNWqtao1ao9aPpXan2t1qqtaoNWqtaoPaoDaqNqgNaqNqg9qgNqo2qA1qo2qD2qA2qjaoDWqjaoPaoDaqNqgNaqNqg9qgNo+JezfuHbnPlft35v7duX/gfgMYovcVBAwAAA==
|
@ -0,0 +1,18 @@
|
||||
|
||||
# Hello World in few languages
|
||||
|
||||
{Worlds}
|
||||
|
||||
Chinese : 你好世界
|
||||
Croatian : Zdravo Svijete
|
||||
Dutch : Hello Wereld
|
||||
English : Hello World
|
||||
French : Bonjour Monde
|
||||
German : Hallo Welt
|
||||
Greek : γειά σου κόσμος
|
||||
Italian : Ciao Mondo
|
||||
Japanese : こんにちは世界
|
||||
Korean : 여보세요 세계
|
||||
Portuguese : Olá Mundo
|
||||
Russian : Здравствулте Мир
|
||||
Spanish : Hola Mundo
|
@ -0,0 +1,18 @@
|
||||
|
||||
# Hello World in few languages
|
||||
|
||||
{Worlds}
|
||||
|
||||
Chinese : 你好世界
|
||||
Croatian : Zdravo Svijete
|
||||
Dutch : Hello Wereld
|
||||
English : NEW VALUE
|
||||
French : Bonjour Monde
|
||||
German : Hallo Welt
|
||||
Greek : γειά σου κόσμος
|
||||
Italian : Ciao Mondo
|
||||
Japanese : こんにちは世界
|
||||
Korean : 여보세요 세계
|
||||
Portuguese : Olá Mundo
|
||||
Russian : Здравствулте Мир
|
||||
Spanish : Hola Mundo
|
@ -0,0 +1 @@
|
||||
X3zNmiTOWEKAG73S8BzrlddMtsozck0eDN7TYwYQv9kswSItWrB31gjJMHtcuGUxFcimtUxtuZ3y0UzoZ8/TBg==
|
@ -0,0 +1,5 @@
|
||||
[Section 1]
|
||||
Key 1.1=Value 1.1
|
||||
Key 1.2=Value 1.2
|
||||
Key 1.3=Value 1.3
|
||||
Key 1.4=Value 1.4
|
@ -0,0 +1,5 @@
|
||||
[Section 1]
|
||||
Key 1.1=Value 1.1
|
||||
Key 1.2=Value 1.2
|
||||
Key 1.3=Value 1.3
|
||||
Key 1.4=Value 1.4
|
@ -0,0 +1,469 @@
|
||||
Imports System
|
||||
Imports System.IO
|
||||
Imports System.Text
|
||||
Imports System.Collections.Generic
|
||||
Imports MadMilkman.Ini
|
||||
|
||||
Module IniSamples
|
||||
|
||||
Private Sub HelloWorld()
|
||||
' Create new file.
|
||||
Dim file As New IniFile()
|
||||
|
||||
' Add new section.
|
||||
Dim section As IniSection = file.Sections.Add("Section Name")
|
||||
|
||||
' Add new key and its value.
|
||||
Dim key As IniKey = section.Keys.Add("Key Name", "Hello World")
|
||||
|
||||
' Read file's specific value.
|
||||
Console.WriteLine(file.Sections("Section Name").Keys("Key Name").Value)
|
||||
End Sub
|
||||
|
||||
Private Sub Create()
|
||||
' Create new file with default formatting.
|
||||
Dim file As New IniFile(New IniOptions())
|
||||
|
||||
' Add new content.
|
||||
Dim section As New IniSection(file, IniSection.GlobalSectionName)
|
||||
Dim key As New IniKey(file, "Key 1", "Value 1")
|
||||
file.Sections.Add(section)
|
||||
section.Keys.Add(key)
|
||||
|
||||
' Add new content.
|
||||
file.Sections.Add("Section 2").Keys.Add("Key 2", "Value 2")
|
||||
|
||||
' Add new content.
|
||||
file.Sections.Add(
|
||||
New IniSection(file, "Section 3",
|
||||
New IniKey(file, "Key 3.1", "Value 3.1"),
|
||||
New IniKey(file, "Key 3.2", "Value 3.2")))
|
||||
|
||||
' Add new content.
|
||||
file.Sections.Add(
|
||||
New IniSection(file, "Section 4",
|
||||
New Dictionary(Of String, String)() From {
|
||||
{"Key 4.1", "Value 4.1"},
|
||||
{"Key 4.2", "Value 4.2"}
|
||||
}))
|
||||
End Sub
|
||||
|
||||
Private Sub Load()
|
||||
Dim options As New IniOptions()
|
||||
Dim iniFile As New IniFile(options)
|
||||
|
||||
' Load file from path.
|
||||
iniFile.Load("..\..\..\MadMilkman.Ini.Samples.Files\Load Example.ini")
|
||||
|
||||
' Load file from stream.
|
||||
Using stream As Stream = File.OpenRead("..\..\..\MadMilkman.Ini.Samples.Files\Load Example.ini")
|
||||
iniFile.Load(stream)
|
||||
End Using
|
||||
|
||||
' Load file's content from string.
|
||||
Dim iniContent As String = "[Section 1]" + Environment.NewLine +
|
||||
"Key 1.1 = Value 1.1" + Environment.NewLine +
|
||||
"Key 1.2 = Value 1.2" + Environment.NewLine +
|
||||
"Key 1.3 = Value 1.3" + Environment.NewLine +
|
||||
"Key 1.4 = Value 1.4"
|
||||
iniFile.Load(New StringReader(iniContent))
|
||||
|
||||
' Read file's content.
|
||||
For Each section In iniFile.Sections
|
||||
Console.WriteLine("SECTION: {0}", section.Name)
|
||||
For Each key In section.Keys
|
||||
Console.WriteLine("KEY: {0}, VALUE: {1}", key.Name, key.Value)
|
||||
Next
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Private Sub Style()
|
||||
Dim file As New IniFile()
|
||||
file.Sections.Add("Section 1").Keys.Add("Key 1", "Value 1")
|
||||
file.Sections.Add("Section 2").Keys.Add("Key 2", "Value 2")
|
||||
file.Sections.Add("Section 3").Keys.Add("Key 3", "Value 3")
|
||||
|
||||
' Add leading comments.
|
||||
file.Sections(0).LeadingComment.Text = "Section 1 leading comment."
|
||||
file.Sections(0).Keys(0).LeadingComment.Text = "Key 1 leading comment."
|
||||
|
||||
' Add trailing comments.
|
||||
file.Sections(1).TrailingComment.Text = "Section 2 trailing comment."
|
||||
file.Sections(1).Keys(0).TrailingComment.Text = "Key 2 trailing comment."
|
||||
|
||||
' Add left space, indentation.
|
||||
file.Sections(1).LeftIndentation = 4
|
||||
file.Sections(1).TrailingComment.LeftIndentation = 4
|
||||
file.Sections(1).Keys(0).LeftIndentation = 4
|
||||
file.Sections(1).Keys(0).TrailingComment.LeftIndentation = 4
|
||||
|
||||
' Add above space, empty lines.
|
||||
file.Sections(2).TrailingComment.EmptyLinesBefore = 2
|
||||
End Sub
|
||||
|
||||
Private Sub Save()
|
||||
Dim options As New IniOptions()
|
||||
Dim iniFile As New IniFile(options)
|
||||
iniFile.Sections.Add(
|
||||
New IniSection(iniFile, "Section 1",
|
||||
New IniKey(iniFile, "Key 1.1", "Value 1.1"),
|
||||
New IniKey(iniFile, "Key 1.2", "Value 1.2"),
|
||||
New IniKey(iniFile, "Key 1.3", "Value 1.3"),
|
||||
New IniKey(iniFile, "Key 1.4", "Value 1.4")))
|
||||
|
||||
' Save file to path.
|
||||
iniFile.Save("..\..\..\MadMilkman.Ini.Samples.Files\Save Example.ini")
|
||||
|
||||
' Save file to stream.
|
||||
Using stream As Stream = File.Create("..\..\..\MadMilkman.Ini.Samples.Files\Save Example.ini")
|
||||
iniFile.Save(stream)
|
||||
End Using
|
||||
|
||||
' Save file's content to string.
|
||||
Dim contentWriter As New StringWriter()
|
||||
iniFile.Save(contentWriter)
|
||||
Dim iniContent As String = contentWriter.ToString()
|
||||
|
||||
Console.WriteLine(iniContent)
|
||||
End Sub
|
||||
|
||||
Private Sub Encrypt()
|
||||
' Enable file's protection by providing an encryption password.
|
||||
Dim options As IniOptions = New IniOptions() With {.EncryptionPassword = "M4dM1lkM4n.1n1"}
|
||||
Dim file As IniFile = New IniFile(options)
|
||||
|
||||
Dim section As IniSection = file.Sections.Add("User's Account")
|
||||
section.Keys.Add("Username", "John Doe")
|
||||
section.Keys.Add("Password", "P@55\/\/0|2D")
|
||||
|
||||
' Save and encrypt the file.
|
||||
file.Save("..\..\..\MadMilkman.Ini.Samples.Files\Encrypt Example.ini")
|
||||
|
||||
file.Sections.Clear()
|
||||
|
||||
' Load and dencrypt the file.
|
||||
file.Load("..\..\..\MadMilkman.Ini.Samples.Files\Encrypt Example.ini")
|
||||
|
||||
Console.WriteLine("User Name: {0}", file.Sections(0).Keys("Username").Value)
|
||||
Console.WriteLine("Password: {0}", file.Sections(0).Keys("Password").Value)
|
||||
End Sub
|
||||
|
||||
Private Sub Compress()
|
||||
' Enable file's size reduction.
|
||||
Dim options As IniOptions = New IniOptions() With {.Compression = True}
|
||||
Dim file = New IniFile(options)
|
||||
|
||||
For i As Integer = 1 To 100
|
||||
file.Sections.Add("Section " + i.ToString()).Keys.Add("Key " + i.ToString(), "Value " + i.ToString())
|
||||
Next
|
||||
|
||||
' Save and compress the file.
|
||||
file.Save("..\..\..\MadMilkman.Ini.Samples.Files\Compress Example.ini")
|
||||
|
||||
file.Sections.Clear()
|
||||
|
||||
' Load and decompress the file.
|
||||
file.Load("..\..\..\MadMilkman.Ini.Samples.Files\Compress Example.ini")
|
||||
|
||||
Console.WriteLine(file.Sections.Count)
|
||||
End Sub
|
||||
|
||||
Private Sub Custom()
|
||||
' Create new file with custom formatting.
|
||||
Dim file As New IniFile(
|
||||
New IniOptions() With {
|
||||
.CommentStarter = IniCommentStarter.Hash,
|
||||
.KeyDelimiter = IniKeyDelimiter.Colon,
|
||||
.KeySpaceAroundDelimiter = True,
|
||||
.SectionWrapper = IniSectionWrapper.CurlyBrackets,
|
||||
.Encoding = Encoding.UTF8
|
||||
})
|
||||
|
||||
' Load file.
|
||||
file.Load("..\..\..\MadMilkman.Ini.Samples.Files\Custom Example Input.ini")
|
||||
|
||||
' Change first section's fourth key's value.
|
||||
file.Sections(0).Keys(3).Value = "NEW VALUE"
|
||||
|
||||
' Save file.
|
||||
file.Save("..\..\..\MadMilkman.Ini.Samples.Files\Custom Example Output.ini")
|
||||
End Sub
|
||||
|
||||
Private Sub Copy()
|
||||
' Create new file.
|
||||
Dim file As New IniFile()
|
||||
|
||||
' Add new content.
|
||||
Dim section As IniSection = file.Sections.Add("Section")
|
||||
Dim key As IniKey = section.Keys.Add("Key")
|
||||
|
||||
' Add duplicate section.
|
||||
file.Sections.Add(section.Copy())
|
||||
|
||||
' Add duplicate key.
|
||||
section.Keys.Add(key.Copy())
|
||||
|
||||
' Create new file.
|
||||
Dim newFile As New IniFile(New IniOptions())
|
||||
|
||||
' Import first file's section to second file.
|
||||
newFile.Sections.Add(section.Copy(newFile))
|
||||
End Sub
|
||||
|
||||
Private Sub Parse()
|
||||
Dim file As New IniFile()
|
||||
Dim content As String = "[Player]" + Environment.NewLine +
|
||||
"Full Name = John Doe" + Environment.NewLine +
|
||||
"Birthday = 12/31/1999" + Environment.NewLine +
|
||||
"Married = Yes" + Environment.NewLine +
|
||||
"Score = 9999999" + Environment.NewLine +
|
||||
"Game Time = 00:59:59"
|
||||
file.Load(New StringReader(content))
|
||||
|
||||
' Map 'yes' value as 'true' boolean.
|
||||
file.ValueMappings.Add("yes", True)
|
||||
' Map 'no' value as 'false' boolean.
|
||||
file.ValueMappings.Add("no", False)
|
||||
|
||||
Dim playerSection As IniSection = file.Sections("Player")
|
||||
|
||||
' Retrieve player's name.
|
||||
Dim playerName As String = playerSection.Keys("Full Name").Value
|
||||
|
||||
' Retrieve player's birthday as DateTime.
|
||||
Dim playerBirthday As DateTime
|
||||
playerSection.Keys("Birthday").TryParseValue(playerBirthday)
|
||||
|
||||
' Retrieve player's marital status as bool.
|
||||
' TryParseValue succeeds due to the mapping of 'yes' value to 'true' boolean.
|
||||
Dim playerMarried As Boolean
|
||||
playerSection.Keys("Married").TryParseValue(playerMarried)
|
||||
|
||||
' Retrieve player's score as long.
|
||||
Dim playerScore As Long
|
||||
playerSection.Keys("Score").TryParseValue(playerScore)
|
||||
|
||||
' Retrieve player's game time as TimeSpan.
|
||||
Dim playerGameTime As TimeSpan
|
||||
playerSection.Keys("Game Time").TryParseValue(playerGameTime)
|
||||
End Sub
|
||||
|
||||
Private Sub BindInternal()
|
||||
Dim file As New IniFile()
|
||||
Dim content As String = "[Machine Settings]" + Environment.NewLine +
|
||||
"Program Files = C:\Program Files" + Environment.NewLine +
|
||||
"[Application Settings]" + Environment.NewLine +
|
||||
"Name = Example App" + Environment.NewLine +
|
||||
"Version = 1.0" + Environment.NewLine +
|
||||
"Full Name = @{Name} v@{Version}" + Environment.NewLine +
|
||||
"Executable Path = @{Machine Settings|Program Files}\@{Name}.exe"
|
||||
file.Load(New StringReader(content))
|
||||
|
||||
' Bind placeholders with file's content, internal information.
|
||||
file.ValueBinding.Bind()
|
||||
|
||||
' Retrieve application's full name, value is 'Example App v1.0'.
|
||||
Dim appFullName As String = file.Sections("Application Settings").Keys("Full Name").Value
|
||||
|
||||
' Retrieve application's executable path, value is 'C:\\Program Files\\Example App.exe'.
|
||||
Dim appExePath As String = file.Sections("Application Settings").Keys("Executable Path").Value
|
||||
End Sub
|
||||
|
||||
Private Sub BindExternal()
|
||||
Dim file As New IniFile()
|
||||
Dim content As String = "[User's Settings]" + Environment.NewLine +
|
||||
"Nickname = @{User Alias}" + Environment.NewLine +
|
||||
"Full Name = @{User Name} @{User Surname}" + Environment.NewLine +
|
||||
"Profile Page = @{Homepage}/Profiles/@{User Alias}"
|
||||
file.Load(New StringReader(content))
|
||||
|
||||
' Bind placeholders with user's data, external information.
|
||||
file.ValueBinding.Bind(
|
||||
New Dictionary(Of String, String)() From
|
||||
{
|
||||
{"User Alias", "Johny"},
|
||||
{"User Name", "John"},
|
||||
{"User Surname", "Doe"}
|
||||
})
|
||||
|
||||
' Bind 'Homepage' placeholder with 'www.example.com' value.
|
||||
file.ValueBinding.Bind(
|
||||
New KeyValuePair(Of String, String)("Homepage", "www.example.com"))
|
||||
|
||||
' Retrieve user's full name, value is 'John Doe'.
|
||||
Dim userFullName As String = file.Sections("User's Settings").Keys("Full Name").Value
|
||||
|
||||
' Retrieve user's profile page, value is 'www.example.com/Profiles/Johny'.
|
||||
Dim userProfilePage As String = file.Sections("User's Settings").Keys("Profile Page").Value
|
||||
End Sub
|
||||
|
||||
Private Sub BindCustomize()
|
||||
Dim file As New IniFile()
|
||||
Dim content As String = "[Player]" + Environment.NewLine +
|
||||
"Name = @{Name}" + Environment.NewLine +
|
||||
"Surname = @{Surname}" + Environment.NewLine +
|
||||
"Adult = @{Age}" + Environment.NewLine +
|
||||
"Medal = @{Rank}"
|
||||
file.Load(New StringReader(content))
|
||||
|
||||
' Customize binding operation.
|
||||
AddHandler file.ValueBinding.Binding,
|
||||
Sub(sender, e)
|
||||
' Set placeholders that do not have a value in data source to 'UNKNOWN'.
|
||||
If Not e.IsValueFound Then
|
||||
e.Value = "UNKNOWN"
|
||||
Return
|
||||
End If
|
||||
|
||||
' Set 'Age' placeholder inside 'Adult' key to an appropriate value.
|
||||
If e.PlaceholderKey.Name.Equals("Adult") AndAlso e.PlaceholderName.Equals("Age") Then
|
||||
Dim age As Integer
|
||||
If Integer.TryParse(e.Value, age) Then
|
||||
e.Value = If((age >= 18), "YES", "NO")
|
||||
Else
|
||||
e.Value = "UNKNOWN"
|
||||
End If
|
||||
Return
|
||||
End If
|
||||
|
||||
' Set 'Rank' placeholder inside 'Medal' key to an appropriate value.
|
||||
If e.PlaceholderKey.Name.Equals("Medal") AndAlso e.PlaceholderName.Equals("Rank") Then
|
||||
Dim rank As Integer
|
||||
If Integer.TryParse(e.Value, rank) Then
|
||||
Select Case rank
|
||||
Case 1
|
||||
e.Value = "GOLD"
|
||||
Exit Select
|
||||
Case 2
|
||||
e.Value = "SILVER"
|
||||
Exit Select
|
||||
Case 3
|
||||
e.Value = "BRONCE"
|
||||
Exit Select
|
||||
Case Else
|
||||
e.Value = "NONE"
|
||||
Exit Select
|
||||
End Select
|
||||
Else
|
||||
e.Value = "UNKNOWN"
|
||||
End If
|
||||
Return
|
||||
End If
|
||||
End Sub
|
||||
|
||||
' Execute binding operation.
|
||||
file.ValueBinding.Bind(New Dictionary(Of String, String)() From {
|
||||
{"Name", "John"},
|
||||
{"Age", "20"},
|
||||
{"Rank", "1"}
|
||||
})
|
||||
End Sub
|
||||
|
||||
' Custom type used for serialization sample.
|
||||
Private Class GameCharacter
|
||||
Public Property Name() As String
|
||||
Get
|
||||
Return m_Name
|
||||
End Get
|
||||
Set(value As String)
|
||||
m_Name = Value
|
||||
End Set
|
||||
End Property
|
||||
Private m_Name As String
|
||||
|
||||
' Serialize this property as a key with "Sword" name.
|
||||
<IniSerialization("Sword")>
|
||||
Public Property Attack() As Double
|
||||
Get
|
||||
Return m_Attack
|
||||
End Get
|
||||
Set(value As Double)
|
||||
m_Attack = value
|
||||
End Set
|
||||
End Property
|
||||
Private m_Attack As Double
|
||||
|
||||
' Serialize this property as a key with "Shield" name.
|
||||
<IniSerialization("Shield")>
|
||||
Public Property Defence() As Double
|
||||
Get
|
||||
Return m_Defence
|
||||
End Get
|
||||
Set(value As Double)
|
||||
m_Defence = value
|
||||
End Set
|
||||
End Property
|
||||
Private m_Defence As Double
|
||||
|
||||
' Ignore serializing this property.
|
||||
<IniSerialization(True)>
|
||||
Public Property Health() As Double
|
||||
Get
|
||||
Return m_Health
|
||||
End Get
|
||||
Set(value As Double)
|
||||
m_Health = value
|
||||
End Set
|
||||
End Property
|
||||
Private m_Health As Double
|
||||
|
||||
Public Sub New()
|
||||
Me.Health = 100
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Private Sub Serialize()
|
||||
Dim file As New IniFile()
|
||||
Dim section As IniSection = file.Sections.Add("User's Character")
|
||||
|
||||
Dim character As New GameCharacter()
|
||||
character.Name = "John"
|
||||
character.Attack = 5.5
|
||||
character.Defence = 1
|
||||
character.Health = 75
|
||||
|
||||
' Serialize GameCharacter object into section's keys.
|
||||
section.Serialize(character)
|
||||
|
||||
' Deserialize section into GameCharacter object.
|
||||
Dim savedCharacter As GameCharacter = section.Deserialize(Of GameCharacter)()
|
||||
|
||||
Console.WriteLine(section.Keys("Name").Value)
|
||||
Console.WriteLine(savedCharacter.Name)
|
||||
Console.WriteLine(section.Keys("Sword").Value)
|
||||
Console.WriteLine(savedCharacter.Attack)
|
||||
Console.WriteLine(section.Keys("Shield").Value)
|
||||
Console.WriteLine(savedCharacter.Defence)
|
||||
End Sub
|
||||
|
||||
Sub Main()
|
||||
HelloWorld()
|
||||
|
||||
Create()
|
||||
|
||||
Load()
|
||||
|
||||
Style()
|
||||
|
||||
Save()
|
||||
|
||||
Encrypt()
|
||||
|
||||
Compress()
|
||||
|
||||
Custom()
|
||||
|
||||
Copy()
|
||||
|
||||
Parse()
|
||||
|
||||
BindInternal()
|
||||
|
||||
BindExternal()
|
||||
|
||||
BindCustomize()
|
||||
|
||||
Serialize()
|
||||
End Sub
|
||||
|
||||
End Module
|
@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{4FEA3A29-874B-4E1B-A60C-584E703FEA11}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<StartupObject>MadMilkman.Ini.Samples.VB.IniSamples</StartupObject>
|
||||
<RootNamespace>MadMilkman.Ini.Samples.VB</RootNamespace>
|
||||
<AssemblyName>MadMilkman.Ini.Samples.VB</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<MyType>Console</MyType>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<DefineDebug>true</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DocumentationFile>MadMilkman.Ini.Samples.VB.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DefineDebug>false</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DocumentationFile>MadMilkman.Ini.Samples.VB.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionExplicit>On</OptionExplicit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionCompare>Binary</OptionCompare>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionStrict>Off</OptionStrict>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionInfer>On</OptionInfer>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="IniSamples.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Application.myapp</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Resources.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Settings.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="My Project\Resources.resx">
|
||||
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
|
||||
<CustomToolNamespace>My.Resources</CustomToolNamespace>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="My Project\Application.myapp">
|
||||
<Generator>MyApplicationCodeGenerator</Generator>
|
||||
<LastGenOutput>Application.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
<None Include="My Project\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<CustomToolNamespace>My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\MadMilkman.Ini\MadMilkman.Ini.csproj">
|
||||
<Project>{bef9735d-c3cc-41e6-aac6-18c5985d3107}</Project>
|
||||
<Name>MadMilkman.Ini</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.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,13 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' This code was generated by a tool.
|
||||
' Runtime Version:4.0.30319.18444
|
||||
'
|
||||
' Changes to this file may cause incorrect behavior and will be lost if
|
||||
' the code is regenerated.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<MySubMain>false</MySubMain>
|
||||
<SingleInstance>false</SingleInstance>
|
||||
<ShutdownMode>0</ShutdownMode>
|
||||
<EnableVisualStyles>true</EnableVisualStyles>
|
||||
<AuthenticationMode>0</AuthenticationMode>
|
||||
<ApplicationType>2</ApplicationType>
|
||||
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
|
||||
</MyApplicationData>
|
@ -0,0 +1,35 @@
|
||||
Imports System
|
||||
Imports System.Reflection
|
||||
Imports System.Runtime.InteropServices
|
||||
|
||||
' General Information about an assembly is controlled through the following
|
||||
' set of attributes. Change these attribute values to modify the information
|
||||
' associated with an assembly.
|
||||
|
||||
' Review the values of the assembly attributes
|
||||
|
||||
<Assembly: AssemblyTitle("MadMilkman.Ini.Samples.VB")>
|
||||
<Assembly: AssemblyDescription("")>
|
||||
<Assembly: AssemblyCompany("")>
|
||||
<Assembly: AssemblyProduct("MadMilkman.Ini.Samples.VB")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2015")>
|
||||
<Assembly: AssemblyTrademark("")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
'The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
<Assembly: Guid("076ab4a2-c8bd-4e3c-bcc2-73829d6c834d")>
|
||||
|
||||
' Version information for an assembly consists of the following four values:
|
||||
'
|
||||
' Major Version
|
||||
' Minor Version
|
||||
' Build Number
|
||||
' Revision
|
||||
'
|
||||
' You can specify all the values or you can default the Build and Revision Numbers
|
||||
' by using the '*' as shown below:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.0.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
@ -0,0 +1,62 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' This code was generated by a tool.
|
||||
' Runtime Version:4.0.30319.18444
|
||||
'
|
||||
' Changes to this file may cause incorrect behavior and will be lost if
|
||||
' the code is regenerated.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
|
||||
Namespace My.Resources
|
||||
|
||||
'This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
'class via a tool like ResGen or Visual Studio.
|
||||
'To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
'with the /str option, or rebuild your VS project.
|
||||
'''<summary>
|
||||
''' A strongly-typed resource class, for looking up localized strings, etc.
|
||||
'''</summary>
|
||||
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0"), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
|
||||
Friend Module Resources
|
||||
|
||||
Private resourceMan As Global.System.Resources.ResourceManager
|
||||
|
||||
Private resourceCulture As Global.System.Globalization.CultureInfo
|
||||
|
||||
'''<summary>
|
||||
''' Returns the cached ResourceManager instance used by this class.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
|
||||
Get
|
||||
If Object.ReferenceEquals(resourceMan, Nothing) Then
|
||||
Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("MadMilkman.Ini.Samples.VB.Resources", GetType(Resources).Assembly)
|
||||
resourceMan = temp
|
||||
End If
|
||||
Return resourceMan
|
||||
End Get
|
||||
End Property
|
||||
|
||||
'''<summary>
|
||||
''' Overrides the current thread's CurrentUICulture property for all
|
||||
''' resource lookups using this strongly typed resource class.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Friend Property Culture() As Global.System.Globalization.CultureInfo
|
||||
Get
|
||||
Return resourceCulture
|
||||
End Get
|
||||
Set(ByVal value As Global.System.Globalization.CultureInfo)
|
||||
resourceCulture = value
|
||||
End Set
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -0,0 +1,73 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' This code was generated by a tool.
|
||||
' Runtime Version:4.0.30319.18444
|
||||
'
|
||||
' Changes to this file may cause incorrect behavior and will be lost if
|
||||
' the code is regenerated.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
|
||||
Namespace My
|
||||
|
||||
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0"), _
|
||||
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Partial Friend NotInheritable Class MySettings
|
||||
Inherits Global.System.Configuration.ApplicationSettingsBase
|
||||
|
||||
Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings)
|
||||
|
||||
#Region "My.Settings Auto-Save Functionality"
|
||||
#If _MyType = "WindowsForms" Then
|
||||
Private Shared addedHandler As Boolean
|
||||
|
||||
Private Shared addedHandlerLockObject As New Object
|
||||
|
||||
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
|
||||
If My.Application.SaveMySettingsOnExit Then
|
||||
My.Settings.Save()
|
||||
End If
|
||||
End Sub
|
||||
#End If
|
||||
#End Region
|
||||
|
||||
Public Shared ReadOnly Property [Default]() As MySettings
|
||||
Get
|
||||
|
||||
#If _MyType = "WindowsForms" Then
|
||||
If Not addedHandler Then
|
||||
SyncLock addedHandlerLockObject
|
||||
If Not addedHandler Then
|
||||
AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
|
||||
addedHandler = True
|
||||
End If
|
||||
End SyncLock
|
||||
End If
|
||||
#End If
|
||||
Return defaultInstance
|
||||
End Get
|
||||
End Property
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
Namespace My
|
||||
|
||||
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
|
||||
Friend Module MySettingsProperty
|
||||
|
||||
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
|
||||
Friend ReadOnly Property Settings() As Global.MadMilkman.Ini.Samples.VB.My.MySettings
|
||||
Get
|
||||
Return Global.MadMilkman.Ini.Samples.VB.My.MySettings.Default
|
||||
End Get
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" UseMySettingsClassName="true">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
Reference in New Issue
Block a user