About Store Forum Documentation Contact



Post Reply 
Need help comparing 2 paks
Author Message
Dandruff Offline
Member

Post: #1
Need help comparing 2 paks
I need help comparing my 2 pak files. They contain no data but just their size etc. I tried to iterate through the files in the paks using this..
Code:
serverpak.file(i).name
and
Code:
clientpak.file(i).name
but i don't know how to use the PakFile struct to compare the files with each other. My goal is to find the files that differ in size and then put those files in a memory container.

Thanks
11-21-2010 10:12 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
RE: Need help comparing 2 paks
get file full path+name Pak::pathName()
find it in second pak Pak::find
11-22-2010 01:01 AM
Find all posts by this user Quote this message in a reply
Dandruff Offline
Member

Post: #3
RE: Need help comparing 2 paks
I can't find the function pathName() but i think you mean fileName(), im going to try it now.
11-22-2010 01:50 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #4
RE: Need help comparing 2 paks
yeah, sorry!
11-22-2010 02:17 AM
Find all posts by this user Quote this message in a reply
Dandruff Offline
Member

Post: #5
RE: Need help comparing 2 paks
smile No problem!

Code:
if((serverpak.find(S+"Game.exe"))&&(!clientpak.find(S+"Game.exe")))StateExit.set(1);

This works. Now i need to replace StateExit with adding the missing file to memory container and replacing (S+"Game.exe") with something more generic.

Is it possible for .find to account for different file sizes and also the time of modification?
(This post was last modified: 11-22-2010 02:35 AM by Dandruff.)
11-22-2010 02:35 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #6
RE: Need help comparing 2 paks
find returns pointer to info about the file
11-22-2010 02:35 AM
Find all posts by this user Quote this message in a reply
Dandruff Offline
Member

Post: #7
RE: Need help comparing 2 paks
Fast smile

Oh right, yes its of type pakfile.
Code:
if((serverpak.find(S+"Game.exe")->data_size)&&(clientpak.find(S+"Game.exe")->data_size))
Like that?

And also, how would you replace (S+"Game.exe")? Would you use an array/memory container or something else?
11-22-2010 02:40 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #8
RE: Need help comparing 2 paks
your code will crash if game.exe is not found
if(C PakFile *pf=pak.find("game.exe"))
{
pf->
}
11-22-2010 02:42 AM
Find all posts by this user Quote this message in a reply
Dandruff Offline
Member

Post: #9
RE: Need help comparing 2 paks
Haha, thanks for that. Adding it in now.
11-22-2010 02:53 AM
Find all posts by this user Quote this message in a reply
Dandruff Offline
Member

Post: #10
RE: Need help comparing 2 paks
Hmm.. this is what i have right now
Code:
        if(C PakFile *pf1=serverpak.find(S+"NxTetra.dll"))            //<---- same files
        {
            if(C PakFile *pf2=clientpak.find(S+"NxTetra.dll"))     //<---- same files
            {
                if((pf2->data_size)==(pf1->data_size))
                //StateExit.set(1);                                    //<--- that works
            }
            else
            {

            }
        }
        else
        {

        }

This is working fine but i can't find a suitable alternative to (S+"NxTetra.dll"). I tried doing this:
Code:
Int i;
...
Bool Update()
{
                ...
        if(i<serverpak.dataSize())i++;        // Should find another place for this
                else {}                  //Should merge all this into a button..
                ...
        if(C PakFile *pf1=serverpak.find(serverpak.file(i).name))       //<----same files
        {
            if(C PakFile *pf2=clientpak.find(serverpak.file(i).name))    //<----same files
            {
                if((pf2->data_size)!=(pf1->data_size))
                                //add to container
            }
            else
            {

            }
        }
        else
        {

        }
}
Is there anything i should change/consider?
(This post was last modified: 11-22-2010 08:01 AM by Dandruff.)
11-22-2010 05:16 AM
Find all posts by this user Quote this message in a reply
Dandruff Offline
Member

Post: #11
RE: Need help comparing 2 paks
I don't understand why this doesn't work. Application dies with unhandled exception?
Code:
    for(i=1;i<=serverpak.totalFiles();i++)
    {
        if(C PakFile *pf1=serverpak.find(serverpak.file(i).name))
        {
            pf1->data_size;
            if(C PakFile *pf2=clientpak.find(serverpak.file(i).name))
            {
                pf2->data_size;
                if((pf2->data_size)!=(pf1->data_size))
                addfile(pf1->name);
            }
            else
            {
                addfile(pf1->name);
    
            }
        }

        else
        {
    
        }
    }

Nevermind, i fixed it. I went over the total number of files in serverpak.
Code:
i<=serverpak.totalFiles()-1

I have a small problem. This works but it only compares the files in the root of the 2 paks and ignores directories. How can i change this so it accounts for its folders too?
Code:
for(i=1;i<=serverpak.totalFiles()-1;i++)
    {
        if(C PakFile *pf1=serverpak.find(serverpak.file(i).name))
        {
            pf1->data_size;
            if(C PakFile *pf2=clientnodata.find(serverpak.file(i).name))
            {// compare pf2(client) with pf1(server). If data_size != server add file to download in mem container
                pf2->data_size;
                if((pf2->data_size)!=(pf1->data_size))
                addfile(pf1->name);
            }
            else
            {// if pf2(client) missing file from pf1(server) add file to other mem container
                addmissing(pf1->name);
    
            }
        }

        else
        {

    
        }
    }

Nevermind again, i had to use serverpak.fileName(i) instead of serverpak.file(i).name
________________________________________________________________________________​______________
Another small problem grin How do i make it so it also adds the full directory of said file and modify it to not add the names of folders into memory?

I just had to replace
Code:
addfile(pf1->name)
with
Code:
addfile(serverpak.fileName(i))
(This post was last modified: 11-23-2010 06:29 AM by Dandruff.)
11-23-2010 04:11 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #12
RE: Need help comparing 2 paks
You need to start with i=0, not 1
just do FREP(..totalFiles())
11-23-2010 10:06 AM
Find all posts by this user Quote this message in a reply
Dandruff Offline
Member

Post: #13
RE: Need help comparing 2 paks
Wow, yea i had no idea why i set it to 1 in the first place.
That define is useful, thanks for that.

I have a question, how can i use the f.operator++(); and f.operator--(); methods?
Can you give an example?
(This post was last modified: 11-27-2010 12:16 AM by Dandruff.)
11-27-2010 12:15 AM
Find all posts by this user Quote this message in a reply
Dandruff Offline
Member

Post: #14
RE: Need help comparing 2 paks
http://pastebin.com/DSPG22Mn

How can i make directories only for folders, not files? I don't know how to check if its a folder or a file. The current code makes folders for everything for example engine.pak -its a folder.

never mind
Code:
FCreateDir(S+"Test/"+GetPath(serverpak.fileName(i)));



________________________________________________________________________________​_____________

[Image: 2lji003.jpg]

When its time to create+download files in "world/area.world", it causes this error. Im not sure if its because of the folder extension, .world, or because of the backslashes. Either way, i don't know how to fix it. I tried doing this but it didn't work so unless something i did here is wrong i think its because of the backslashes.
Code:
void dlthread1(Str file)
{
    File f;
    if(GetExt(file)!=NULL)               //If not a folder
    {
        if(GetExt(file)!=S+"world")    //World/area.world is a folder though so skip it
            f.write(S+"Test/"+file);
        else
            StateExit.set(1);              //Doesn't do anything
    }
    filedownload1.create(S+serverclient+file);
    filedownload1.wait();

    f.put(filedownload1.data(),filedownload1.totalSize());
}


Just realized this won't work with the world files (they don't have file type extensions). Gotta think of something else..
(This post was last modified: 11-30-2010 07:50 AM by Dandruff.)
11-28-2010 09:34 AM
Find all posts by this user Quote this message in a reply
Post Reply