pathcfiles using innition and run is looks broken

If i use this code it works great:

            p = Patchfile()
            p.apply(Filename(file),Filename('tmp2aw.mf'))

If i use more fancy progress bar code it does not work but leave the file tmp2aw.mf untouched. It also appears to except any file as a patch file.

            p = Patchfile()
            p.initiate(Filename(file),Filename('tmp2aw.mf'))
            while p.getProgress() != 1.0 and p.run():
                progress = p.getProgress()
                info = "applying %s: %.2f%% "%(file,progress*100.)
                self.bar.setText(info)
                self.bar.setValue(progress)
                yield None # continuation pause

Maybe i am doing some thing wrong and there is better ways to patch with progress bar?

When the progress reaches 1, the temp file has not replaced the original one yet. Call run() once more to finalise its job.
God just saved me again, so I can figure it out even without reading the source. :smiley:

If you did read the source, you would see this for the definition of Patchfile::apply():

bool Patchfile::
apply(Filename &patch_file, Filename &file) {
  int ret = initiate(patch_file, file);
  if (ret < 0)
    return false;
  for (;;) {
    ret = run();
    if (ret == EU_success)
      return true;
    if (ret < 0)
      return false;
  }
  return false;
}

Which loop you should imitate if you call run() directly instead of calling apply(). That is, you should call run() until it returns EU_success (meaning successful completion) or a negative number (meaning failure). Checking get_progress() is incorrect.

David

I think i was checking progress due to the run() returning 1 no matter how long it was running. It did not look like it was returning any other number but 1.

I will look more.

EU_success is 1. It should return this number only upon successful completion.

Incidentally, you should of course use the symbol names, defined in panda/src/express/error_utils.h, instead of their numeric values (which are subject to change from one version of Panda to the next). The Python name for EU_success is EUSuccess.

David

in many cases the doc’s dont say what they return
panda3d.org/apiref.php?page=Patchfile

Yeah, I know. Would you like to volunteer to improve these docs? It would just mean changing the comments in the C++ code.

David

sure.

Maybe we could create some sort of a DB/wiki for the reference too and let people change/comment on it and merge the change back into the comments in the code?