Skip to content

Commit 35ee798

Browse files
committed
init commit
0 parents  commit 35ee798

23 files changed

+2011
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.vs
2+
NCodeParser/bin
3+
NCodeParser/obj
4+
packages

NCodeParser.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.28803.156
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NCodeParser", "NCodeParser\NCodeParser.csproj", "{1C1BC9C4-6184-4201-A4D1-0C37D789C46B}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{1C1BC9C4-6184-4201-A4D1-0C37D789C46B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{1C1BC9C4-6184-4201-A4D1-0C37D789C46B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{1C1BC9C4-6184-4201-A4D1-0C37D789C46B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{1C1BC9C4-6184-4201-A4D1-0C37D789C46B}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {37ACFDE7-30D7-427A-9EBB-EB55D932797E}
24+
EndGlobalSection
25+
EndGlobal

NCodeParser/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>

NCodeParser/App.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application x:Class="NCodeParser.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
StartupUri="View/MainWindow.xaml"
7+
d1p1:Ignorable="d" >
8+
</Application>

NCodeParser/App.xaml.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace NCodeParser
10+
{
11+
/// <summary>
12+
/// App.xaml에 대한 상호 작용 논리
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}

NCodeParser/Enum.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace NCodeParser
8+
{
9+
public enum NovelType
10+
{
11+
Normal,
12+
R18,
13+
Kakuyomu
14+
};
15+
}

NCodeParser/Extensions.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace NCodeParser
8+
{
9+
public static class Extensions
10+
{
11+
public static void AddAll<T>(this IList<T> List, IList<T> Collection)
12+
{
13+
if (List == null || Collection == null)
14+
{
15+
return;
16+
}
17+
18+
for (int i = 0; i < Collection.Count; i++)
19+
{
20+
List.Add(Collection[i]);
21+
}
22+
}
23+
}
24+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Net;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace NCodeParser.IO
9+
{
10+
public class CookieAwareWebClient : WebClient
11+
{
12+
public CookieContainer CookieContainer
13+
{
14+
get;
15+
private set;
16+
}
17+
18+
public CookieAwareWebClient()
19+
{
20+
CookieContainer = new CookieContainer();
21+
}
22+
23+
protected override WebRequest GetWebRequest(Uri address)
24+
{
25+
var Request = (HttpWebRequest) base.GetWebRequest(address);
26+
Request.CookieContainer = CookieContainer;
27+
28+
return Request;
29+
}
30+
}
31+
}

NCodeParser/IO/INIManager.cs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using IniParser;
8+
using IniParser.Model;
9+
using IniParser.Parser;
10+
using NCodeParser.Model;
11+
12+
namespace NCodeParser.IO
13+
{
14+
public class INIManager
15+
{
16+
private readonly string NovelDataPath = "Data.ini";
17+
18+
private IniData NovelData;
19+
private FileIniDataParser Parser;
20+
21+
public INIManager()
22+
{
23+
Parser = new FileIniDataParser();
24+
25+
if (File.Exists(NovelDataPath))
26+
{
27+
NovelData = Parser.ReadFile(NovelDataPath);
28+
}
29+
else
30+
{
31+
NovelData = new IniData();
32+
}
33+
}
34+
35+
public List<Novel> GetNovels()
36+
{
37+
var NovelList = new List<Novel>();
38+
39+
foreach (var SectionData in NovelData.Sections)
40+
{
41+
string Code = SectionData.Keys["Code"];
42+
if (string.IsNullOrWhiteSpace(Code))
43+
{
44+
continue;
45+
}
46+
47+
string Type = SectionData.Keys["Type"];
48+
if (string.IsNullOrWhiteSpace(Type))
49+
{
50+
continue;
51+
}
52+
53+
string Desc = SectionData.Keys["Desc"];
54+
55+
bool IsSuccess = Enum.TryParse(Type, out NovelType NovelType);
56+
if (!IsSuccess)
57+
{
58+
continue;
59+
}
60+
61+
NovelList.Add(new Novel
62+
{
63+
Code = Code,
64+
Type = NovelType,
65+
Desc = Desc
66+
});
67+
}
68+
69+
return NovelList;
70+
}
71+
72+
public bool SetNovels(IList<Novel> Novels)
73+
{
74+
try
75+
{
76+
NovelData.Sections.Clear();
77+
78+
for (int i = 0; i < Novels.Count; i++)
79+
{
80+
if (string.IsNullOrWhiteSpace(Novels[i].Code))
81+
{
82+
Novels.RemoveAt(i);
83+
i--;
84+
85+
continue;
86+
}
87+
88+
NovelData[string.Format("Novel{0:D4}", i + 1)]["Code"] = Novels[i].Code;
89+
NovelData[string.Format("Novel{0:D4}", i + 1)]["Type"] = Novels[i].Type.ToString();
90+
NovelData[string.Format("Novel{0:D4}", i + 1)]["Desc"] = Novels[i].Desc;
91+
}
92+
93+
Parser.WriteFile(NovelDataPath, NovelData, Encoding.UTF8);
94+
}
95+
catch
96+
{
97+
98+
}
99+
100+
return false;
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)