Oni Central Forum

A forum for the Oni community

You are not logged in.

#151 01/30/08 13:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Okay, I think we're basically on the same page.  I see now how the other folder is useful.  So how about this:

1. Check .tga (that is what we're using, right?) files in Modified against level0. -- me
2. Make list of newly changed files. -- me
3. Copy those files to Work. -- you
4. Batch convert the Work folder, sending the converted .oni files to Temp. -- you
5. Move any .oni files in level0 with a name that matches a file in Temp to Backup (unless already there, in which case delete them). -- me
6. Move all (.oni) files in Temp to level0. -- you
7. Clean up Work and Temp folders. -- you

Optionally we can present a dialog between 2 and 3 showing which files will be converted and sent to level0, and a dialog before step 5 deletes anything, with mod. dates so the user can confirm that the files are not needed.  Since the script put the files in Work and Temp, the script can delete those files without notice.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#152 01/30/08 14:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Let me save you some work.

1) User selects file or folder of .tga files to convert to .oni files (done)
2) Duplicate file/s to Work folder (done)
3) Convert file/s to .oni file and move .oni files to Temp (done)
4) Move duplicated .tga image files to Modified as backup (done)
5) Make backup of .oni files -- Iritscen
6) Move all (.oni) files in Temp to level0. -- EdT
7) Clean up Temp folders -- EdT

That was easy smile

Last edited by EdT (01/30/08 14:01)

Offline

#153 01/30/08 14:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Okay, fine, you twisted my arm into saving myself work smile

So tomorrow all I will post is the code that compares mod. dates so we know what files to back up and which not to.  You can then work it into all the code you've already written.  At least some of the work I did over the weekend was not in vain!


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#154 01/30/08 14:01

geyser
Member
From: beyond the veil
Registered: 01/14/07
Website

Re: Mac programming

Keep in mind that the creation date of the "original" .oni files can be posterior to that of a "new" .oni file supposed to replace the "old" one.
My shell scripts just check if a file has already been backed up, and if it hasn't, we assume it has never been modded yet and back it up...
And if a backup is already present, we don't "back it up again" (that would overwrite the backup with a modded file): that's all there is to it.

Last edited by geyser (01/30/08 14:01)


Behold the power of that which is yet unborn! For the swirling images that flow forth from the Chrysalis are only a shadow of the sleeper's true power.

Offline

#155 01/30/08 14:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Yeah, I guess so.  Okay, then, I'm totally useless after all.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#156 01/30/08 16:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Iritscen: No you're not! smile

We still need code for step 5.  Backing up the original TXMP.oni files, as they're modded. As geyser states, if the original files are already in the Backup folder, then there is no need to copy them again.

And I have no idea how to make such comparisons, so you still have work to do!

Last edited by EdT (01/30/08 16:01)

Offline

#157 01/31/08 10:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Okay, here's some little snippets of code presented as tutorials.  You've gotten quite good at integrating things like this on your own, so rather than presenting any unified code, I'll just how you the things you need to know.

Q. How do I check if a file or folder already exists?
A. Where "my_path" is a path in typical Mac format (colon-separated), say:

if (folder my_path exists) then

Obviously you substitute "file" for "folder" when checking that a file exists.  (I used this in my prototype script TXMP Replacer to check that the Backup and Modified folders exist.  If they don't, do you know how to create them via AppleScript?)

Q. How do I do a run-through of a folder's files to check each one for something?
A.

set file_ct to count of files in folder TXMP_Modified_folder
repeat with x from 1 to file_ct
   set a to file x in folder TXMP_Modified_folder -- this gets the whole file's info
   set b to (name of file a as text) -- get just the name of the file
end repeat

Q. How do I make a list of files to do something with?
A. Optionally declare a variable like this beforehand: "the_list = {}".  Then, when you have a filepath you want to store in the list, say:

copy (name of source_file as text) to end of the_list

Q. How do I check for which file is newer between a pair I'm comparing?
A. Declare a couple of number variables, like x and y, and set them like this:

set x to modification date of file1 -- a string with file1's path
set y to modification date of file2

Then use a three-part 'if' series like this:

if (y is greater than x) then -- this means that file2 is newer
--do something
else if (x is greater than y) then -- this might be a problem if file1 is not supposed to be newer, say, if it's the file in level0_Final
--present error dialog or add this file's name to a list of problems to present to user
else -- the only other possibility is that the files are the same, which probably means taking no action at all with this file
--you may not care about this option, in which case you don't need the else statement at all, but this sample just shows how to cover all your bases
end if

Q. How do I compare files with different suffixes, such as checking that a modded .tga-format TXMP is newer than the .oni version of that same TXMP in level0_Final?
A. If you go through a folder getting each file's path and name using the above code, you already have the name of, say, the .tga version of the file.  It's easy to add things to strings using the ampersand (&) to concatenate, but what if you have written code that looks for the existence of a file with the same name but a different suffix?  You need to subtract something from the end before you can add a new suffix.  Use this code to strip a suffix:

on strip_suffix(file_path)
    set last_period to 0
    set path_lgth to count of characters in file_path
    set period to "."
    
    repeat with x from 1 to path_lgth
        if (character x in file_path is period) then
            set last_period to x
        end if
    end repeat
    
    repeat with x from 1 to (last_period - 1)
        set character x of suffixless_path to character x of file_path
    end repeat
    
    return suffixless_path
end strip_suffix

You can use it like this:

set new_path to my strip_suffix(old_path)
set new_path to new_path & ".oni"

Now you have a file with the same path and name as before,  but the suffix that you need in order to check if it exists.  So you could get the name of each .tga file in, say, the Modified folder, and look for that file in level0_Final with the .oni suffix.

Well, this ends our tutorial for today.  I basically just shot a bunch of code at you with an AppleScript shotgun, have fun piecing it together  smile  I still have other code I wrote over last weekend that I won't post unless you need it -- path manipulation stuff.  Let me know if you have questions on the above.

Last edited by Iritscen (01/31/08 10:01)


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#158 01/31/08 18:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

You're making me work??? tongue Hopefully, tomorrow, I'll have time to study the HOMEWORK you gave me smile

Offline

#159 02/01/08 09:02

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Actually, if I could have posted a unified program, I would have, but I never finished it for lack of time this week and also because I saw you were already ahead of me in doing the same overall work.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#160 02/04/08 09:02

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Iritscen: I didn't get a chance to work on your homework smile But here is the logic of what I think needs to be done:

Loop through files in Oni/TXMPfiles/Temp
    If filename does not exist in Oni/TXMPfiles/Backup
        move filename from Oni/GameDataFolder/level0_Final to Oni/TXMPfiles/Backup
    end if
    move filename to Oni/GameDataFolder/level0_Final
End loop

What do you think?

In AE Tools, I already have the code "set parentFolder to container of (path to me)"

So, if you could write the Applescript code for this part, I'd greatly appreciate it.

Offline

#161 02/04/08 09:02

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Sorry, maybe I overloaded you with code.  Are you asking for me to write the part you outline in your post, moving the modified file to the level0 folder and the original to the backup folder?  If so, no problem, I will do it tonight.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#162 02/04/08 10:02

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Yes, Please do so.  Then I can learn a bit more Applescript from your code.

Offline

#163 02/05/08 10:02

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Sorry, it didn't happen last night, I was busy installing Windows on my Mac tongue  Hopefully soon.

Edit: Oh yeah, I wanted to ask: do you see the AE Tools becoming a front-end for onisplit?  I mean actually providing a GUI for everything onisplit does.  We seem to be headed in that direction and I wondered if you wanted to do that.  It could also be argued that the onisplit GUI could be a separate app from the tool for installing the Edition.

Last edited by Iritscen (02/05/08 11:02)


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#164 02/05/08 12:02

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

I was about to ask you that question.  With OniSplit having more features, the current GUI for AETools is not adequate and will have too much clutter.
.
Is there a way in xCode to have a menu for OniSplit that will open a new window for OniSplit tools?
(Actually, I made myself a simple App for OniSplit to test the various commands)

Offline

#165 02/05/08 13:02

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

What do you mean by a menu for OniSplit?

We can certainly go the AE Tools route and have a OniSplit Tools.app that sits in Oni/ or somewhere.  It can either require that onisplit be somewhere specific (which raises the question of whether we use the Edition's copy of onisplit or our own copy somewhere else), or we can have the user find it in a dialog and save the path for future reference.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#166 02/05/08 13:02

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

I was thinking that within AETools, there could be a menu or button that open a window just for OniSplit Tools.
Just like in your AE Installer, the Advanced button, lead to more options.

So instead of 2 apps, AETools and OniSplitTools, they would be combined into a single app.  Those wanting to use OniSplit would have a separate window to use.

Offline

#167 02/05/08 13:02

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

We could do that, although what would we call the combined app?  It's both a tool for the Edition and a tool for using OniSplit, which are not necessarily related tasks.

I'm not sure how to use Xcode to make a second window.  In AppleScript, it's easy because you're dismissing the dialog and getting the result before displaying another dialog, but it's a different paradigm in Xcode.  Of course, using Xcode is preferable because we can do more than three buttons at a time.  I can look into it.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#168 02/08/08 10:02

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Okay, here's the program I call TXMP Replacer.  Probably you are going to end up cutting out the useful bits and folding it into OniSplit Tools, but here it is in its entirety.  It worked for me last night, but I can't guarantee it's foolproof, so before using this, back up any files that you place in TXMPModified, and back up the original .oni versions in level0 too, just to be safe.

Instructions:
- make sure that, inside TXMPfiles, you have made the folders TXMPModified (where you put your .tgas), TXMPConverted (empty), and TXMPBackup (empty or holding the original .oni files already) beforehand.  The script can't currently make those folders if they're missing, but it will report on the problem.
- compile this script as an application bundle and place in Oni's main folder.

Comments:
- Make sure that you haven't already placed any modded TXMPs in level0 yourself, or that, if you have, they're not newer than the copy of those TXMPs in TXMPModified, or the TXMPModified versions will not get converted and sent to level0.  It's unlikely this will happen to you, but I had this problem myself and thought it was a bug in TXMP Replacer until I actually looked at mod. dates and realized it was my fault for putting something newer in level0 manually before using the program.
- TXMP Replacer will attempt to convert any file in TXMPModified if it finds a file with that name in level0 (ending in .oni).  So, not only should it handle Targa files (tested), it should handle the other formats onisplit converts to TXMPs (not tested), and it will also try to convert any other kind of file you put there, like a modified TRAM (that's a problem you have to avoid causing).  Of course, why would you put non-TXMP files in TXMPModified?
- Feel free to rename the folders for your version of this code, but the names were the most logical ones I could think of.  I also have many others folders in TXMPfiles (my categories that I filed the TXMPs into), so naming them "TXMP___" keeps them easily distinguishable from all the other folders.
- There's a good few support functions here, some of which may surprise you.  For instance, notice that I don't use POSIX path anywhere in this code.  That code has been absorbed into my support functions.  I prefer this DIY approach, because I can exactly predict what the output will be when I write the code.  One of the support functions is currently unused: find_parent_path_UNIX, so you may wish to not bother carrying it over.
- If you're experiencing trouble, uncomment the display dialog lines.  The output can be very helpful in finding a problem.


I'm sure I forgot to explain something or other, so feel free to ask questions!


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#169 02/08/08 12:02

geyser
Member
From: beyond the veil
Registered: 01/14/07
Website

Re: Mac programming

Late reply:
"It's both a tool for the Edition and a tool for using OniSplit, which are not necessarily related tasks."
Being able to use OniSplit at all can be presented as part of the Anniversary Edition (or... Addition?).
Heh, looks like I just coined a new word for the project. Either AEdition or AEddition. Woohoo, eh? smile


Behold the power of that which is yet unborn! For the swirling images that flow forth from the Chrysalis are only a shadow of the sleeper's true power.

Offline

#170 02/08/08 13:02

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Yeah, but using OniSplit can also be presented as a modding tool, and most people will just want to install the Edition for playing purposes.  So we're considering making a modder-oriented tool (OniSplit Tools or whatever) and a separate installer for the Edition that just focuses on the features that players need to have.

"Addition" would be really confusing.  "AEdition" is a good abbreviation, though.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#171 02/08/08 16:02

geyser
Member
From: beyond the veil
Registered: 01/14/07
Website

Re: Mac programming

I would keep things combined as a single GUI, with preset and advanced regimes.
In the advanced regime, people can do whatever the blam they want with OniSplit
(as long as they don't touch their backed up content, as per by the Edition's rules).
And at any time they can run a bunch of installation scripts (either ours or theirs).

I only hesitated between "AEdition" and "AEddition" (merging "addition" in, sorta).
I agree the latter is confusing more than anything else. I'll prob'ly use "aedition".

Last edited by geyser (02/08/08 16:02)


Behold the power of that which is yet unborn! For the swirling images that flow forth from the Chrysalis are only a shadow of the sleeper's true power.

Offline

#172 02/08/08 19:02

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

We might also consider adding the OBj viewer to the mix! smile

Offline

#173 02/10/08 23:02

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Iritscen: Your script works well!  I will add it to AETools. Hopefully, this week, I can try to update it, I'm thinking of using tabs to separate AETools and OniSplit Tools.  But first gotta figure out tabs in xCode...

Offline

#174 02/11/08 10:02

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Good luck with that :->  Never got around to figuring that out myself.

Okay, so here's how I spent all my free time on the weekend: you know how obj_view comes with scripts, which make it oh-so-much-easier to launch one of the sample weapons in obj_view?  Well, they're .bats, so they don't work on Macs.  It's easy to convert them to .sh scripts, which I did, but I figured that it was still too much work to run those from the Terminal (you can't click-and-run with .shs like you can with .bats in Windows), and it's also a pain to make a new script manually every time you have a new object you want to make a shortcut for.  So I wrote this app (attached).

Installation Instructions:
Unzip the package.  Unzip the app and scriptsMac folders and place them in the same directory (viewer/) as obj_view.  You must have the "original" directory in the same folder as the "viewer" folder.  In other words, like this:

obj_view/
--viewer/
----obj_view (the executable)
----scripts/
----scriptsMac/
----OBJViewer Assistant.app
--original/
----(the .objs and .tgas you want to open with obj_view)
--imported/

Running OBJViewer Assistant will allow you to run any .sh in scriptsMac, or to make a new one by picking a .obj and a .tga from the "original" folder.

What If I Get a "Permission Denied" Error?
The shell script in scriptsMac probably didn't have permission to execute on your system.  Run the "Give Scripts Executability" app in scriptsMac to fix the prpblem.  Note that this will not work if you do not have administrator privileges on your Mac.  Also, scripts newly created on your machine with the Assistant should automatically be given execution privileges, but again, this will not work if you aren't an admin on your computer.  There is no "workaround" for this limitations; it is a feature of OS X's security that cannot be circumvented.

Known bugs/limitations:
- Can only work with files in original/.
- Determines name of script on its own based on name of .obj file.
- Cannot create a new script using an .obj that already was made into another script because of the auto-naming limitation above.
- Stays open while obj_view is open, causing a timeout after you're in obj_view for a while.  No adverse effect on obj_view, but still annoying.

Obviously I should be taking care of those bugs/limitations at some point, but I wanted to post what I have so you can bug-test, EdT.  It works for me, at least as well as the obj_view itself works, obj_view's bugs notwithstanding.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#175 02/11/08 10:02

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Very Nice!  Now we need to make a AETools/OSTools/OBjAsst all in one program! big_smile

Offline

Board footer

Powered by FluxBB