Skip to content

Commit 6ef91c4

Browse files
committed
Adding creating a configuration file if it did not exist before.
1 parent 3a310c1 commit 6ef91c4

File tree

4 files changed

+39
-37
lines changed

4 files changed

+39
-37
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@ Implements reading and modification of configuration files such as INI, ENV.
66

77
#### .NET CLI
88
```CLI
9-
> dotnet add package Hopex.MultiConfX --version 23.0.1
9+
> dotnet add package Hopex.MultiConfX --version 23.0.2
1010
```
1111

1212
#### Package Manager
1313
```CLI
14-
PM> NuGet\Install-Package Hopex.MultiConfX -Version 23.0.1
14+
PM> NuGet\Install-Package Hopex.MultiConfX -Version 23.0.2
1515
```
1616

1717
#### PackageReference
1818
```XML
19-
<PackageReference Include="Hopex.MultiConfX" Version="23.0.1" />
19+
<PackageReference Include="Hopex.MultiConfX" Version="23.0.2" />
2020
```
2121

2222
#### Paket CLI
2323
```CLI
24-
> paket add Hopex.MultiConfX --version 23.0.1
24+
> paket add Hopex.MultiConfX --version 23.0.2
2525
```
2626

2727
#### Script & Interactive
2828
```CLI
29-
> #r "nuget: Hopex.MultiConfX, 23.0.1"
29+
> #r "nuget: Hopex.MultiConfX, 23.0.2"
3030
```
3131

3232
#### Cake
3333
```
3434
// Install Hopex.MultiConfX as a Cake Addin
35-
#addin nuget:?package=Hopex.MultiConfX&version=23.0.1
35+
#addin nuget:?package=Hopex.MultiConfX&version=23.0.2
3636
3737
// Install Hopex.MultiConfX as a Cake Tool
38-
#tool nuget:?package=Hopex.MultiConfX&version=23.0.1
38+
#tool nuget:?package=Hopex.MultiConfX&version=23.0.2
3939
```
4040

4141
# Opportunities

src/MultiConfX/Env/Env.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,26 @@ public EnvData Load()
119119
/// <returns><see langword="true"/>, if the data was written to the file without errors.</returns>
120120
public bool Save()
121121
{
122-
if (File.Exists(GetPath()))
122+
if (!File.Exists(path: GetPath()))
123+
File.Create(path: GetPath()).Dispose();
124+
125+
using (StreamWriter streamWriter = new StreamWriter(
126+
path: GetPath(),
127+
append: false
128+
))
123129
{
124-
using (StreamWriter streamWriter = new StreamWriter(GetPath()))
130+
Data.GetKeys().ForEach(action: key =>
125131
{
126-
Data.GetKeys().ForEach(action: key =>
127-
{
128-
var @keyFormatted = LineFormatter.KeyForEnv(key: key);
129-
var @valueFormatted = LineFormatter.Value(value: Data.Keys[keyFormatted]);
130-
131-
streamWriter.WriteLine(
132-
value: $"{keyFormatted}={valueFormatted}"
133-
);
134-
});
135-
}
132+
var @keyFormatted = LineFormatter.KeyForEnv(key: key);
133+
var @valueFormatted = LineFormatter.Value(value: Data.Keys[keyFormatted]);
136134

137-
return true;
135+
streamWriter.WriteLine(
136+
value: $"{keyFormatted}={valueFormatted}"
137+
);
138+
});
138139
}
139140

140-
return false;
141+
return true;
141142
}
142143

143144
/// <summary>

src/MultiConfX/Ini/Ini.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,27 +136,28 @@ public IniData Load()
136136
/// <returns><see langword="true"/>, if the data was written to the file without errors.</returns>
137137
public bool Save()
138138
{
139-
if (File.Exists(path: GetPath()))
139+
if (!File.Exists(path: GetPath()))
140+
File.Create(path: GetPath()).Dispose();
141+
142+
using (StreamWriter streamWriter = new StreamWriter(
143+
path: GetPath(),
144+
append: false
145+
))
140146
{
141-
using (StreamWriter streamWriter = new StreamWriter(path: GetPath()))
147+
Data.GetSections().ForEach(action: section =>
142148
{
143-
Data.GetSections().ForEach(action: section =>
149+
streamWriter.WriteLine(value: $"[{section.Trim()}]");
150+
Data.GetKeys(section).ForEach(action: key =>
144151
{
145-
streamWriter.WriteLine(value: $"[{section.Trim()}]");
146-
Data.GetKeys(section).ForEach(action: key =>
147-
{
148-
var @keyFormatted = LineFormatter.KeyForIni(key: key);
149-
var @valueFormatted = LineFormatter.Value(value: Data.Sections[section][key]);
152+
var @keyFormatted = LineFormatter.KeyForIni(key: key);
153+
var @valueFormatted = LineFormatter.Value(value: Data.Sections[section][key]);
150154

151-
streamWriter.WriteLine(value: $"{keyFormatted}={valueFormatted}");
152-
});
155+
streamWriter.WriteLine(value: $"{keyFormatted}={valueFormatted}");
153156
});
154-
}
155-
156-
return true;
157+
});
157158
}
158159

159-
return false;
160+
return true;
160161
}
161162

162163
/// <summary>

src/MultiConfX/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// Можно задать все значения или принять номера сборки и редакции по умолчанию
3333
// используя "*", как показано ниже:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("23.0.0.1")]
36-
[assembly: AssemblyFileVersion("23.0.0.1")]
35+
[assembly: AssemblyVersion("23.0.0.2")]
36+
[assembly: AssemblyFileVersion("23.0.0.2")]

0 commit comments

Comments
 (0)