This repository has been archived by the owner on Sep 3, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
380 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,4 +227,7 @@ _Pvt_Extensions | |
.paket/paket.exe | ||
|
||
# FAKE - F# Make | ||
.fake/ | ||
.fake/ | ||
|
||
# Custom | ||
*.dat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<configSections> | ||
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > | ||
<section name="SteveCadwallader.CodeMaid.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> | ||
</sectionGroup> | ||
</configSections> | ||
<userSettings> | ||
<SteveCadwallader.CodeMaid.Properties.Settings> | ||
<setting name="Reorganizing_MemberTypeConstructors" serializeAs="String"> | ||
<value>Constructors||2||Instantiation</value> | ||
</setting> | ||
<setting name="Reorganizing_RegionsInsertNewRegions" serializeAs="String"> | ||
<value>True</value> | ||
</setting> | ||
<setting name="Reorganizing_RegionsRemoveExistingRegions" serializeAs="String"> | ||
<value>True</value> | ||
</setting> | ||
<setting name="Reorganizing_MemberTypeFields" serializeAs="String"> | ||
<value>Fields||1||Members</value> | ||
</setting> | ||
<setting name="Reorganizing_RunAtStartOfCleanup" serializeAs="String"> | ||
<value>True</value> | ||
</setting> | ||
<setting name="Cleaning_UpdateEndRegionDirectives" serializeAs="String"> | ||
<value>False</value> | ||
</setting> | ||
<setting name="Cleaning_InsertBlankLinePaddingBeforePropertiesSingleLine" | ||
serializeAs="String"> | ||
<value>True</value> | ||
</setting> | ||
</SteveCadwallader.CodeMaid.Properties.Settings> | ||
</userSettings> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace OpenNos.Core | ||
{ | ||
public static class DatParser | ||
{ | ||
#region Members | ||
|
||
private const string datEntryOffset = "END"; | ||
|
||
#endregion | ||
|
||
#region Methods | ||
|
||
public static IEnumerable<TDTO> Parse<TDTO>(string filePath) | ||
{ | ||
IList<TDTO> parsedResults = new List<TDTO>(); | ||
|
||
string[] plainEntries = Regex.Split(File.ReadAllText(filePath).Replace("\r", "\n"), datEntryOffset); | ||
|
||
//load all qualified import properties | ||
IEnumerable<PropertyInfo> importProperties = typeof(TDTO).GetProperties() | ||
.Where(prop => prop.IsDefined(typeof(ImportAttribute), false)); | ||
|
||
//iterate thru all dat entries | ||
foreach (string plainEntry in plainEntries) | ||
{ | ||
var parsedEntry = Activator.CreateInstance<TDTO>(); | ||
|
||
//iterate thru all qualified import properties | ||
foreach (PropertyInfo importProperty in importProperties) | ||
{ | ||
ImportAttribute attribute = importProperty.GetCustomAttribute<ImportAttribute>(); | ||
var value = ParseLineIndex(plainEntry, attribute); | ||
|
||
if(value != null && value != "-1") | ||
{ | ||
importProperty.SetValue(parsedEntry, Convert.ChangeType(value, importProperty.PropertyType)); | ||
} | ||
} | ||
|
||
parsedResults.Add(parsedEntry); | ||
} | ||
|
||
return parsedResults; | ||
} | ||
|
||
private static string ParseIndex(string line, ImportAttribute attribute) | ||
{ | ||
return Regex.Split(line, @"\s")[attribute.Index]; | ||
} | ||
|
||
private static string ParseLine(string entry, ImportAttribute attribute) | ||
{ | ||
return Regex.Match(entry, $"^.*{attribute.Line}.*$", RegexOptions.Multiline).Value; | ||
} | ||
|
||
private static string ParseLineIndex(string entry, ImportAttribute attribute) | ||
{ | ||
string line = ParseLine(entry, attribute); | ||
|
||
//check if line has been found | ||
if (!String.IsNullOrEmpty(line)) | ||
{ | ||
return ParseIndex(line, attribute); | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"{attribute} not found."); | ||
Debug.WriteLine($"{attribute} not found in {entry}"); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
|
||
namespace OpenNos.Core | ||
{ | ||
public class ImportAttribute : Attribute | ||
{ | ||
#region Instantiation | ||
|
||
public ImportAttribute(string line, int index) | ||
{ | ||
Line = line; | ||
Index = index; | ||
} | ||
|
||
#endregion | ||
|
||
#region Properties | ||
|
||
public int Index { get; set; } | ||
|
||
public string Line { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return $"Line: {Line}, Index: {Index}"; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
|
||
namespace OpenNos.Data | ||
{ | ||
public class User | ||
public class UserDTO | ||
{ | ||
#region Properties | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using OpenNos.Core; | ||
using OpenNos.Data; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace OpenNos.Import.Console | ||
{ | ||
public class ImportFactory | ||
{ | ||
private string _folder; | ||
|
||
public ImportFactory(string folder) | ||
{ | ||
_folder = folder; | ||
} | ||
|
||
public void ImportItems() | ||
{ | ||
string file = $"{_folder}\\Item.dat"; | ||
IEnumerable<ItemDTO> items = DatParser.Parse<ItemDTO>(file); | ||
|
||
int i = 0; | ||
} | ||
} | ||
} |
Oops, something went wrong.