Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Pages: [1] 2  All

Author Topic: How exactly does Copy File work?  (Read 6569 times)

0 Members and 1 Guest are viewing this topic.

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
How exactly does Copy File work?
« on: August 13, 2010, 12:06:51 AM »

Hi again,

I decided to put some unlockable extras into my game and now I'm not sure how I can access and copy those specific segments to a folder of my choice. I read that the safest bet is to use the savegame folder because it's supposed to be always writable. That's fine with me. So here is the code I tried as a test:

Code: WME Script
  1. var Bonus = new File("extras/test.png");
  2. Bonus.Close();
  3.  

And that did not work. Then I tried to specifiy a filename as well with
Code: WME Script
  1. Bonus.Copy(Game.SaveDirectory + "\Extra01_test.png");
  2.  

But it did not work either. I also tried to see what it returns by putting it into Game.Msg(); and it always returned false.

Where do I do wrong?

Thanks in advance
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: How exactly does Copy File work?
« Reply #1 on: August 13, 2010, 07:59:12 AM »

Hi.

first of all I am not sure if this copy-way of doing extra is a good approach, I'd hide unlockables to package but it's just my choice.

As this code worked for me:
Code: WME Script
  1. var file = new File("testfile.bin");
  2. file.Copy(Game.SaveDirectory + "/testfile.bin");
  3.  

check the following:

1. in your copy command revert \ to /
2. Double check the saved game path actually exists on your drive (it's created only after the first savegame has been created)
3. Triple check the file is not already in the target path. If so, you have to specify optional parameter overwrite.
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: How exactly does Copy File work?
« Reply #2 on: August 13, 2010, 02:02:35 PM »

Hi meta, thanks for the reply.

I'm not sure I understood you right about the hide unlockables to package. Did you mean you'd create a package exclusively to them?

Anyway. I don't have a .bin to test it with but I tried it with various other files. It didn't work.
I went through the check list you gave me as well, I can confirm I checked all of that and it's in proper order.
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: How exactly does Copy File work?
« Reply #3 on: August 13, 2010, 04:03:02 PM »

Darky,

I tried with many files and it always works. where exactly is your extras folder located? Try copying the file to your root (eg where wpr file is located) and start from there.
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: How exactly does Copy File work?
« Reply #4 on: August 13, 2010, 05:37:51 PM »

Hi meta,

I tried your suggestion with interesting results:
Copying file from root (where .wpr is) to any other location: Works
Copying file from inside a regular folder (no package) to somewhere else: Works
Copying file from inside package to somewhere else (root, savegame folder, etc): Does not work!

The "extras" folder is located in /data which is pretty much the original WME package. It seems only to copy when the file is in a non-package.

Why doesn't it work from inside other packages?
« Last Edit: August 13, 2010, 05:40:10 PM by Darky »
Logged

odnorf

  • w00t?
  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 7
  • Offline Offline
  • Gender: Male
  • Posts: 1454
  • Lamp dog!
    • View Profile
Re: How exactly does Copy File work?
« Reply #5 on: August 13, 2010, 06:10:43 PM »

That's by design. Dot.Copy(); doesn't extract files from within packages.
Logged
fl*p

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: How exactly does Copy File work?
« Reply #6 on: August 13, 2010, 06:20:42 PM »

Exactly. Only reading is supported from files stored in your game packages (DCP files). (as documentation states)
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: How exactly does Copy File work?
« Reply #7 on: August 13, 2010, 06:31:38 PM »

Although I read that line in the doc's too, I didn't make the connection (it didn't say "only", just "also"). That's what you get for making assumptions...  ::slug

What's the best way to put the unlockables in without the Users directly seeing them?
« Last Edit: August 13, 2010, 06:33:32 PM by Darky »
Logged

Jyujinkai

  • Global Moderator
  • Frequent poster
  • *
  • Karma: 1
  • Offline Offline
  • Posts: 350
    • View Profile
    • Jyujinkai's WME Development Blog
Re: How exactly does Copy File work?
« Reply #8 on: August 13, 2010, 06:40:20 PM »

this entire method seams flawed. What exactly is the nature of the unlockables... there are a number of ways depending on what you are looking for to do this in a much better way.
Logged
<Antoine de Saint-Exupéry> In any thing at all, perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away...
<Carl Sagan> If you want to make a apple pie from scratch. You must first... invent the universe

odnorf

  • w00t?
  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 7
  • Offline Offline
  • Gender: Male
  • Posts: 1454
  • Lamp dog!
    • View Profile
Re: How exactly does Copy File work?
« Reply #9 on: August 13, 2010, 06:43:42 PM »

What's the best way to put the unlockables in without the Users directly seeing them?

Just put the data in the data files and use a variable to check whether a condition is met to use them. Forget what I said. I misunderstood. You probably mean something like Larry6 wallpapers added in gamedir when doing certain actions.
« Last Edit: August 13, 2010, 06:45:25 PM by odnorf »
Logged
fl*p

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: How exactly does Copy File work?
« Reply #10 on: August 13, 2010, 06:57:29 PM »

Yes, like Larry ;) Mostly various Wallpapers for your Desktop. Otherwise I'd have probably made a in-game gallery of bonus content like some other games do :)
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: How exactly does Copy File work?
« Reply #11 on: August 14, 2010, 01:12:29 AM »

How about doing something like this (UNTESTED!):

Code: WME Script
  1.  
  2. var file1 = new File("your file in dcp");
  3. file1.OpenAsBinary(1);
  4.  
  5. var file2 = new File("your targetfile");
  6. file2.OpenAsBinary(2);
  7.  
  8. var b = 0;
  9. while ((b = file1.ReadByte())!=null) //it's 2AM and I'm not sure this construction works in WME, so I'm just giving you an idea here :)
  10. {
  11.    file2.WriteByte(b);
  12. }
  13.  
  14. file1.Close();
  15. file2.Close();
  16.  
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: How exactly does Copy File work?
« Reply #12 on: August 15, 2010, 05:16:44 AM »

Hi meta, thanks for the pointer. It looks good in your post but the condition for the loop doesn't seem to work with WME (it crashes). I first tried it as is as except I added a Sleep to the end of the loop.

After that I also tried some other variants of the loop I could think of but it didn't really work. At one point I got it as far as copying bytes to the target file but it wouldn't stop and repeat itself even though I specified that it should stop when file1.ReadByte() returns null. I'd post the code but I can't access it right now, I probably do that later.

Anyway just wanted to let you know about the result. Thanks everyone so far for the great help with this :)
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5679
    • View Profile
    • Dead:Code Site
Re: How exactly does Copy File work?
« Reply #13 on: August 15, 2010, 09:00:40 AM »

The file object has a Length property, so you can simply do a loop from 0 to Length. But I think it will be slow.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: How exactly does Copy File work?
« Reply #14 on: August 15, 2010, 03:01:31 PM »

Mnemonic, it works but really is too slow for productive use. The duration to finish can take a few seconds if its just a few kb up to over 10 minutes depending on the file size. It's a good method for small textfiles or so but not for anything bigger like Wallpapers.

I used meta's method with this loop:
Code: WME Script
  1. Game.LOG("Starting File Copy...");
  2. var b = 0;
  3. while(b < file1.Length && b != null)
  4. {
  5.     b = file1.ReadByte();
  6.     file2.WriteByte(b);
  7.     Sleep(1); // i had it on 10 before, but I also tested it on 1 for a faster speed
  8. }
  9. Game.LOG("Finished File Copy!");
  10.  
Logged
Pages: [1] 2  All
 

Page created in 0.207 seconds with 22 queries.