Project Perfect Mod Forums
:: Home :: Get Hosted :: PPM FAQ :: Forum FAQ :: Privacy Policy :: Search :: Memberlist :: Usergroups :: Register :: Profile :: Log in to check your private messages :: Log in ::


The time now is Fri Apr 19, 2024 9:29 pm
All times are UTC + 0
New utility born!
Moderators: Community Tools Developpers
Post new topic   Reply to topic Page 1 of 1 [10 Posts] Mark the topic unread ::  View previous topic :: View next topic
Author Message
John Galt
Commander


Joined: 01 Aug 2003
Location: Galt's Gulch

PostPosted: Tue Nov 11, 2003 5:17 pm    Post subject:  New utility born! Reply with quote  Mark this post and the followings unread

Last week's chat with iceman559 gave me another idea: a duplicate section finder/wiper. I found some free time and after 30 minutes of coding, here it is.

It's pretty stable (there aren't many chances for you to do anything wrong.. except clicking something bedfore loading INI file Wink )

However, two notes:
1: Due to RA2/TS non-standard INI coding (allowing side-comments), standard ini parsing controls don't work properly. So I have three choices:
a) eat up user's CPU time by building a comment-free copy;
b) ask him to use INI checker to wipe the comments
c) ask him to use Wordpad/Editpad to replace all comment mark symbols with newline and comment mark.

Right now I prefer options b or c. So, get rid of the comments before using this...

2: although you choose which sections to delete, it probably deletes the first one it finds with the same name. Beware...

Anyway, enjoy!

And I'm sorry about not making an AI Randomizer as promised Crying or Very sad , but this small thing fit perfectly into my free time Smile

Screenie:



sections.jpg
 Description:
 Filesize:  41.88 KB
 Viewed:  4111 Time(s)

sections.jpg



Back to top
View user's profile Send private message Visit poster's website Skype Account
stucuk
Geek


Joined: 27 Aug 2002

PostPosted: Wed Nov 12, 2003 1:10 am    Post subject: Reply with quote  Mark this post and the followings unread

Tip: to get it to delete the correct duplicate store the line number of each section so you can easily delete the correct one.

type
tsectionpos = Array of packed record
line_no : Cardinal;
end;

var
sectionpos : tsectionpos;

usage:

When loading the file

count := 0;
setlength(sectionpos,0);

for x := 0 to linesofsomething.count-1 do
if this line contains a section then
begin
count := count +1;
setlength(sectionpos,count+1);
sectionpos[count].line_no := x;
end;

When working out the location

The sectionpos number should be the same as the component you use to store the information(im guessing a ListView1)

the line number for a particular section would b something like

sectionpos[listview1.whateverisselected].line_no

Note: not everything above is actual delphi code, without correction it wouldn't work int he real world, the bits in italics are english words not delphi code

Hope this helps you.

P.S DELPHI RULZ!!!!!!

Quote:
However, two notes:
1: Due to RA2/TS non-standard INI coding (allowing side-comments), standard ini parsing controls don't work properly. So I have three choices:
a) eat up user's CPU time by building a comment-free copy;
b) ask him to use INI checker to wipe the comments
c) ask him to use Wordpad/Editpad to replace all comment mark symbols with newline and comment mark.


what do you mean?(i wonder what comments have to do with deleting duplicate sections)

imo you should add hints to the buttons so ppl know exactly what there for (arrow pointing downwards means nothing to me)

a menu system would b nice too.

_________________
Free Map Editor - Game Requirements - Stucuk.Net

Back to top
View user's profile Send private message Visit poster's website
John Galt
Commander


Joined: 01 Aug 2003
Location: Galt's Gulch

PostPosted: Wed Nov 12, 2003 6:28 am    Post subject: Reply with quote  Mark this post and the followings unread

Because I'm just a beginner, I used the easiest way of INI parsing - Delphi's parsing unit INIFiles, which checks for sections this way:

read a line from file
if (S[1] = '[') and (S[Length(S)] = ']') then
add to sectionlist

Obviously, it doesn't accept comments ... I'm not skilled enough to make my own INI parser, and modifying this line in the INIFiles.pas doesn't seem to affect anything, I wonder why? Sad

I really need to learn more about coding... I'll be looking at the whole unit today, to get some ideas about how is that parser made and try to make something similar. Thanks for your ideas, they're really helpful.

Back to top
View user's profile Send private message Visit poster's website Skype Account
stucuk
Geek


Joined: 27 Aug 2002

PostPosted: Wed Nov 12, 2003 2:22 pm    Post subject: Reply with quote  Mark this post and the followings unread

Nobody wrote:
Because I'm just a beginner, I used the easiest way of INI parsing - Delphi's parsing unit INIFiles, which checks for sections this way:

read a line from file
if (S[1] = '[') and (S[Length(S)] = ']') then
add to sectionlist

Obviously, it doesn't accept comments ... I'm not skilled enough to make my own INI parser, and modifying this line in the INIFiles.pas doesn't seem to affect anything, I wonder why? Sad

I really need to learn more about coding... I'll be looking at the whole unit today, to get some ideas about how is that parser made and try to make something similar. Thanks for your ideas, they're really helpful.


Im guessing this is a delphi 7(i see you have the profesional version) only file, never knew it existed.(i use Delphi 4 and 6 mainly)

The way i "parse" info is like so:

if (copy(richedit1.lines.strings[x],1,1) = '[') and (copy(richedit1.lines.strings[x],length(richedit1.lines.strings[x])-1,1) = ']') then

works the same, yours is the simple way.

what do u mean you don't know how to parse comments? Lines that have a comment half way through it? Lines that start with a comment?

_________________
Free Map Editor - Game Requirements - Stucuk.Net

Back to top
View user's profile Send private message Visit poster's website
John Galt
Commander


Joined: 01 Aug 2003
Location: Galt's Gulch

PostPosted: Wed Nov 12, 2003 3:00 pm    Post subject: Reply with quote  Mark this post and the followings unread

I use Delphi 6 too, and it's in there, in /Source/rtl/Common/inifiles.pas , just adding INIFiles to unit's Uses statement works.

I mean if a file is built like this:
Quote:
[YURI] ; yuri clone

, it'll prevent the program from adding the line to the section list. If a simple line has a comment, it doesn't matter in this case. But my INI Checker had this pain, and I didn't know any solutions, so it silently built a comment-free copy of the opened file in tem0.ini, and used it for every operation.

And about hta INIFiles unit... is it me, or do the built-in units ignore modifications? I changed the mentioned line to
if ((S[1] = '[') and (Pos(']',S)<>0)) then
... saved it, recopmpiled, but nothing changed Sad
weird, and I don't know how to solve it.

Back to top
View user's profile Send private message Visit poster's website Skype Account
stucuk
Geek


Joined: 27 Aug 2002

PostPosted: Wed Nov 12, 2003 5:48 pm    Post subject: Reply with quote  Mark this post and the followings unread

copy the line into your program.

are there comments on the same line as section "headings" in the original RA2 / YR rules ?

_________________
Free Map Editor - Game Requirements - Stucuk.Net

Back to top
View user's profile Send private message Visit poster's website
John Galt
Commander


Joined: 01 Aug 2003
Location: Galt's Gulch

PostPosted: Wed Nov 12, 2003 6:20 pm    Post subject: Reply with quote  Mark this post and the followings unread

Yes, there are. Why?

Back to top
View user's profile Send private message Visit poster's website Skype Account
stucuk
Geek


Joined: 27 Aug 2002

PostPosted: Wed Nov 12, 2003 6:41 pm    Post subject: Reply with quote  Mark this post and the followings unread

btw ur modifyed line will work. Just copy the section that does the ini stuff you want to your program.

_________________
Free Map Editor - Game Requirements - Stucuk.Net

Back to top
View user's profile Send private message Visit poster's website
John Galt
Commander


Joined: 01 Aug 2003
Location: Galt's Gulch

PostPosted: Wed Nov 12, 2003 7:05 pm    Post subject: Reply with quote  Mark this post and the followings unread

Yo mean the whole modified procedure/function, right? I'll try that and see what happens. Thanks for the advice.

Back to top
View user's profile Send private message Visit poster's website Skype Account
stucuk
Geek


Joined: 27 Aug 2002

PostPosted: Wed Nov 12, 2003 7:38 pm    Post subject: Reply with quote  Mark this post and the followings unread

just everything that is needed(some procedures have other stuff in them you don't need)

_________________
Free Map Editor - Game Requirements - Stucuk.Net

Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [10 Posts] Mark the topic unread ::  View previous topic :: View next topic
 
Share on TwitterShare on FacebookShare on Google+Share on DiggShare on RedditShare on PInterestShare on Del.icio.usShare on Stumble Upon
Quick Reply
Username:


If you are visually impaired or cannot otherwise answer the challenges below please contact the Administrator for help.


Write only two of the following words separated by a sharp: Brotherhood, unity, peace! 

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © phpBB Group

[ Time: 0.1878s ][ Queries: 14 (0.0094s) ][ Debug on ]