β How to make a program that can read this?
I know how to open and read files. But in this case its not as simple as reading every line.
There is a structure in the file which the program has to understand.
Things are belligerent aren't preset keywords but in game names.
What would be a good way of being able to read this file?
97 Replies
Is this a defined format or some one off thing?
Its a defined format by Paradox
Do they provide a serialization library for it or at least a spec?
You could probably write a parser fairly easily. There is a nuget called pidgin that helps a lot
Not that Im aware off
I used it to write a
bencode
parser a few days agodefinitely look at pidgin and do some research into "syntax parsing"
Alright will do
Thanks
So I tried installing the package but than I got this?
I installed packages before and no error was given
.net framework
π§
looks like you'll have to use an older version of it that supports that framework
or stop using .NET Framework if you have a choice
Ah so the package doesnt support it
I see
the latest version doesn't
looks like 2.5.0 is the last one that targets anything below .NET 5
Pidgin 2.5.0
A lightweight, fast, and flexible parsing library for C#, developed at Stack Overflow.
I see, thanks for checking it out for me
Time to make my own parsing library xD
or just use that older version if it still does the job
i'm assuming you're stuck on .netfx because this is some kind of mod
if not then definitely use a newer version of .NET
Yeah that is probatly the more sane idea
yeah the only reason to still be using .NET Framework is if you have some external requirement that forces you to
Well, it is a Windows Forms App
Winforms works fine with .net 7
Stop using framework if you can
I cant seem to select the new framework for my project
even though the installer says I do have it installed
you can't, you'll have to rebuild it from scratch
Makes sense
Still hate it
or, more usefully, create a brand new WinForms project in .NET 5+, to see what it looks like, and manually change over your existing .csproj
or even MORE usefully, also stop using WinForms
Haha and than use what?
WPF, UWP, MAUI, etc.
I think there's a tag for this...
$gui
hang on
Im hanging on
$guiframeworks
Windows Presentation Foundation (WPF):
+ Has a lot of resources online due to how old it is.
+ There are a lot of UI libraries for it
- No longer maintained, as in, didn't receive any major updates since a long time.
Universal Windows Platform (UWP):
+ Fast, and has a small binary size.
+ Has a nice UI out of the box (And also there's WinUI 2.7 to achieve Windows 11's looks and feel).
- Is packaged and requires a developer license.
Avalonia:
+ Cross-platform and is under active development.
- Relatively new, so there are not a lot of online resources for it.
Note: All of the mentioned GUI frameworks are XAML-based.
hmmm, the one I was thinking of has even more options
Which is?
there's Xamarin.Forms, which is geared towards cross-platform mobile apps
there's MAUI which also geared towards cross-platform mobile, but with Microsoft leanings
there's WinUI which is the most "modern" Windows platform, like if you want to deploy to the Windows Store
if all you care about is running on the Windows Desktop, go with WPF or Avalonia
and protip: if you're gonna do this, you definitely SHOULD learn about the MVVM pattern, and XAML, but you 100% do not have to. You can still write traditional imperative UI apps if you want a lower barrier to entry
Hhhmm okay
Will have to look into that than
So I tried reading the file byte for byte but wtf are those \0
that looks like you read each line into an array much longer than the actual text
\0
is a null character, which is the same as a byte with a value of 0
since it's text based you should be using text-oriented reading APIsI run a foreach on the line so that shouldn't be possible
i'd have to see code
tempBytes = new byte[999];
string tempWord = Encoding.ASCII.GetString(tempBytes);
you are converting the entire array into a string when you only want part of itOooo
Ofcourse
Stupid me haha
I preset the length of the array so he takes the whole array
Thanks
what's the goal of this code? it seems like you're stripping out non alphanumeric (or printable?) characters but there are significantly easier ways to do that
Well my goal hasnt changed since the beginning of this post
i know what your overall goal is
but what's this specific code doing
Its all for the game hearts of iron 4. The modding there is done by scripting using a langue created by the developers of the game. I though it would be a fun hobby project to try making a interface for modding it.
that's the opposite direction of specificity i was going for lol
the code you posted, just describe the things it's doing
While within the game countries have there ideologies. The diffrent kind of possible ideologies are defined in that file.
that isn't describing what that code is doing
What do you want from me haha
just go through the code and explain what each part does
because i'm trying to help you avoid writing something overcomplicated
You do ReadLines, then treat each line as a byte array when it's a string. Why?
first line is useless no clue why its needed.
than we have the name for a ideology (belligerent).
than its defining three diffrent subideologies and setting if it can be randomly selected by a country
than its defining three possible faction names for countrie with those ideology
than the color for that ideology is set
than same more variables. just a lot of setting I better things to do than writing this you get the point haha
Just trying ways to read a file to find out what works
Dude, we are not asking about the files content..we are asking about why your code is really weird
yes, the structure of the file you're trying to read is clear
your code is not
for example, why are you doing
that seems like an overcomplicated way to remove certain characters from the text
Why is there a byte array at all? It's already a string, why are you doing encoding on your own etc
frankly i wouldn't read it as lines anyway, the file structure implies it is not sensitive to line breaks, only whitespace
for example,
color
looks like its value is an array of numbers but the whole thing is on one lineWell how would I be able to get the word "belligerent" from the file if I dont read it byte for byte to find out when the word started and stopped?
Other things are predefined and could be looked at with string.Contains
text.IndexOf("belligerent")
But it has to be dynamic
what isn't dynamic about that?
"belligerent"
so don't use a string literal
use a variable that holds the text you want to search for
But I dont now what I want to search for at the start
That is defined in the file
That is when the name for the ideology is defined
also, reading text byte for byte is actually incorrectly assuming its encoding fwiw
Yuup
You're actually reading the ascii values
Ah okay
My bad
i mean, it looks like it'll work here but it may not later and then you'll run into problems
it's more of a coincidence that the file is only using ASCII characters
All the files only use ASCII characters as far as Im aware off
The files relevant for this project
is there a reason you aren't pursuing the parser library pobiega suggested?
seems like a good fit since this format is practically "json but different"
Challenges are fun
i mean yeah, if your goal is to learn to write a parser go for it
And since my project is outdated
I would have to convert that which sucks
you should do that anyway
True true
But here is my second argument
you could even use this which i've had decent luck with updating legacy projects https://dotnet.microsoft.com/en-us/platform/upgrade-assistant
Im to stubbornly
I like to write my own code
you'll need to get over that if you want to be productive in an environment like a job
But maybe, just maybe it is better to just do that
for learning sure it's fine
I know, it is that this is a hobby project
but if you want to learn effectively, don't restrict yourself to outdated tools for no reason
Fair enough
Well, something to add to my tasks for tomorrow
Thanks again for your help. I'm going to bed
<a:PU_PepeWave:775091969311244289>
Cant seem to select it though? Am I missing something here?
As you've already been told, you need to re-create your project
there was a hard break between .NET Framework 4.8 and .NET 5 (technically earlier than that, but w/e)
you cant just set a higher framework version, everything has changed.
new SDK, new base class library, new runtime..
That was in the project create screen
you picked the wrong project type
go back
$newproject
When creating a new project, prefer using .NET over .NET Framework, unless you have a very specific reason to be using .NET Framework.
.NET Framework is now legacy code and only get security fix updates, it no longer gets new features and is not recommended.
https://cdn.discordapp.com/attachments/569261465463160900/899381236617855016/unknown.png
avoid the NOs, pick a green one
if you want winforms, thats the one that says "yes, but prefer WPF"
What is the reason to avoid those?
oo wait
read the text
I feel like a idiot but thanksπ
.NET 4.8 came out in 2017. .NET 7 was last november, and .net 8 will be out this november
.net framework is "dead"
.NET is the modern, living version
Yeah I understand
fantastic
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.