Skip to content

Commit

Permalink
Few small quality of life tweaks. Updated to 0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lordvoldem0rt committed Feb 23, 2023
1 parent 5222580 commit 7210f39
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 8 deletions.
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased] - yyyy-mm-dd

To be announced

### Added

### Changed

### Fixed

## [v0.2.2] - 2023-02-23

Few small quality of life tweaks

### Changed

- Changed output to include '-modified' suffix to the filename
- Output window stays open if an error has occured

### Fixed

- Fixed uncaught error when duplicate keys appeared in the CSV

## [v0.2.1] - 2023-02-04

Fixed bug where quotes in CSV files were being double escaped when converting to BIN

## [v0.2.0] - yyyy-mm-dd

Added support to convert .csv to .bin

## [v0.1.0] - yyyy-mm-dd

Initial release that supports BIN to JSON and JSON to BIN
5 changes: 4 additions & 1 deletion Parseltongue.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AssemblyName>Parseltongue</AssemblyName>
<RootNamespace>Parseltongue</RootNamespace>
<IsPackable>false</IsPackable>
<Version>0.2.0</Version>
<Version>0.2.2</Version>
<ApplicationIcon>snake-head.ico</ApplicationIcon>
</PropertyGroup>

Expand All @@ -29,6 +29,9 @@
<None Update="SampleFiles\language.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="SampleFiles\SUB-enUS.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
29 changes: 25 additions & 4 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,18 @@ private static void CsvToBin(FileInfo file)
{
using (var csv = new CsvReader(reader, config))
{
var records = csv.GetRecords<Foo>();
entries = records.ToDictionary(r => r.key, r => r.value.Replace(@"\\n", @"\n"));
try
{
var records = csv.GetRecords<Foo>();
entries = records.ToDictionary(r => r.key, r => r.value.Replace(@"\\n", @"\n"));
}
catch (Exception e)
{
Console.WriteLine(e);
Console.WriteLine("Press Enter key to close...");
Console.ReadLine();
return;
}
}
}

Expand All @@ -123,6 +133,13 @@ private static void JsonToBin(FileInfo file)
WriteBinFromDictionary(file.FullName, entries);
}

static string AddSuffix(string filename, string suffix)
{
string fDir = Path.GetDirectoryName(filename);
string fName = Path.GetFileNameWithoutExtension(filename);
string fExt = Path.GetExtension(filename);
return Path.Combine(fDir, String.Concat(fName, suffix, fExt));
}

private static void WriteBinFromDictionary(string file, Dictionary<string, string> entries)
{
Expand All @@ -132,7 +149,9 @@ private static void WriteBinFromDictionary(string file, Dictionary<string, strin
return;
}

using (var fs = File.Open(Path.ChangeExtension(file, ".bin"), FileMode.Create))
string modifiedPath = AddSuffix(file,"-modified");

using (var fs = File.Open(modifiedPath, FileMode.Create))
{
using (var bw = new BinaryWriter(fs, Encoding.UTF8, false))
{
Expand Down Expand Up @@ -238,7 +257,9 @@ private static void BinToJson(FileInfo file)
}

var jsonString = JsonConvert.SerializeObject(entries, Formatting.Indented);
File.WriteAllText(Path.ChangeExtension(file.FullName, ".json"), jsonString);

string modifiedPath = AddSuffix(file.FullName,"-modified");
File.WriteAllText(modifiedPath, jsonString);
}
}

Expand Down
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ For specify a certain convertor

### Examples

`Parseltongue.exe language.bin` will output `language.json`
`Parseltongue.exe language.bin` will output `language-modified.json`

`Parseltongue.exe language.json` will output `language.bin`
`Parseltongue.exe language.json` will output `language-modified.bin`

`Parseltongue.exe json2bin language_json.txt` will output `language_json.bin`
`Parseltongue.exe json2bin language_json.txt` will output `language_json-modified.bin`

## Notes

Expand All @@ -55,3 +55,34 @@ CSV conversion has only been tested with a `.csv` exported from Google Sheets
- Snake Icon by [Vectors Market](https://iconscout.com/icons/snake-head)
- Testers from the [Hogwarts Legacy Modding](https://discord.gg/Bmmtv3sYAa) discord server:
- [tucker](https://hamstersquad.github.io/)

## Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

### [v0.2.2] - 2023-02-23

Few small quality of life tweaks

#### Changed

- Changed output to include '-modified' suffix to the filename
- Output window stays open if an error has occured

#### Fixed

- Fixed uncaught error when duplicate keys appeared in the CSV

### [v0.2.1] - 2023-02-04

Fixed bug where quotes in CSV files were being double escaped when converting to BIN

### [v0.2.0] - yyyy-mm-dd

Added support to convert .csv to .bin

### [v0.1.0] - yyyy-mm-dd

Initial release that supports BIN to JSON and JSON to BIN
Binary file added snake-head.ico
Binary file not shown.

0 comments on commit 7210f39

Please sign in to comment.