Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Development

Cookies? Writing to hard drive saved preferences..??

Author Message
JimNayzium



Joined: 17 Jul 2007
Posts: 6

Posted: Wed Aug 08, 2007 - 3:46 pm    Post subject: Cookies? Writing to hard drive saved preferences..?? Reply with quote

I am developing a game widget, and would like for game-preferences to be saved locally on a person's hard-drive.

Is there a tutorial link anyone could recommend or is this even possible?

Thanks.

I have already enabled system control as the game loads other files already on a person's hard drive they download...but writing to a predetermined txt file and saving that to the hard drive is the hurdle now.
View user's profile Send private message Send e-mail Widgets
Greenie



Joined: 08 Jun 2005
Posts: 81

Posted: Wed Aug 08, 2007 - 5:36 pm    Post subject: it is possible Reply with quote

Hi,

I don't know about your knowledge about programming in general, so this might be a bit short, but basically it is possible to read and write files from/to the users harddrive.
What you have to use is the widget.system-command. This way you can invoke shell-commands for example which in turn could read from (and probably write to, I am no unix-guru) the filesystem.
I myself made some tests with invoking the osx built-in php-interpreter via the widget.system-command. The interpreter ran a php-script which did the work regarding the read/write-accesss and that worked quite nicely. If you know about php this is probably one of the easiest ways to do what you want.
View user's profile Send private message Send e-mail AIM Address ICQ NumberWidgets
JimNayzium



Joined: 17 Jul 2007
Posts: 6

Posted: Wed Aug 08, 2007 - 5:45 pm    Post subject: Reply with quote

I do know php really well...in chunks...that i have been forced to learn along and along...I can author an xml file dynamically using the readdir and the write commands etc...

but am a tad unclear how this will help me...meaning, the php engine is used, writes the file insdie the package contents...then uses that php file to load hte preferences etc....

Can you give me the shell commands I will need as I am really green on the terminal stuff...
View user's profile Send private message Send e-mail Widgets
Greenie



Joined: 08 Jun 2005
Posts: 81

Posted: Thu Aug 09, 2007 - 1:34 pm    Post subject: This way... Reply with quote

Okay, here's the important part of what I was doing. Not only the system-call-part but some other things just to make clear how it is working.

In Javascript I set up some variables like this:

Code:
pathToPhpScripts = "./phpscripts/";   // folder within the widgets' own folder
phpReadFile = "loadFile.php";   // the php-file to call
pathToPhpInterpreter = "/usr/bin/php ";   // standard path to php-interpreter


Then I set up a javascript function like this (the part after the php-interpreter (the arguments) are in quotes):

Code:
function getData(){
   var myListName = "de.xml";
   widget.system(pathToPhpInterpreter + pathToPhpScripts + phpReadFile + " '" + pathToLocalList + myListName + "'",showPhpOutput);
}


What the above function does is to set up an asynchronous system-call. The last parameter "showPhpOutput" is a reference to a function that will handle the output. It is called as soon as the php-script sends something back. For testing-purposes it is sufficient to write something like this (again in Javascript):

Code:
function showPhpOutput(myObj){
   alert(decodeURIComponent(myObj.outputString));
}


"myObj" is an object that automatically holds whatever the php-script sent back. "outputString" is a property that holds the actual test. "decodeURIComponent" is used because the system-call seems to have problems with all sorts of non-standard-ascii-characters. The simple files I tried seemed to load fine when using the "decodeURIComponent"-function.

And finally the (absolutely basic) php-file called "loadFile.php". All it does is to take the parameter I gave it above (file and pathname), reads the file and echoes the results back. And this is the point when the "ShowPhpOutput"-javascript-function reacts on what the php script has given back.

Code:
<?php
$file_contents = file_get_contents($argv[1]);
$file_contents = rawurlencode($file_contents);
echo $file_contents
?>


Hope this helps. If not, just ask again (maybe per email if you want to).

Stephan

PS: Just wanted to mention the app-document about using system-calls. There you will find additional infos about what the system-call can do and what info you can collect from it:

http://developer.apple.com/documentation/AppleApplications/Reference/Dashboard_Ref/GadgetObj/chapter_2_section_3.html#//apple_ref/doc/uid/TP40001339-CH203-DontLinkElementID_21
View user's profile Send private message Send e-mail AIM Address ICQ NumberWidgets
JimNayzium



Joined: 17 Jul 2007
Posts: 6

Posted: Thu Aug 09, 2007 - 3:00 pm    Post subject: Reply with quote

Thanks a ton. I will give it a try.

Is it just me, or does this site often run the words off the right edge without wrapping properly?? I use Safari 2.0.4 in Mac 10.4.8
View user's profile Send private message Send e-mail Widgets
Greenie



Joined: 08 Jun 2005
Posts: 81

Posted: Thu Aug 09, 2007 - 6:10 pm    Post subject: Yep, same problem here Reply with quote

Hi,

I have the same problem regarding too long lines, I use Safari, latest 2.x-version and latest OSX 10.4.x update. Thought it would because one the extensions I installed for safari.

Greetings,

Stephan
View user's profile Send private message Send e-mail AIM Address ICQ NumberWidgets
Greenie



Joined: 08 Jun 2005
Posts: 81

Posted: Thu Aug 09, 2007 - 6:18 pm    Post subject: One last thing... Reply with quote

Hi again,

I guess you already know this, but just in case: Alert-messages from within widgets are shown in the console that is found in the OSX-utilities-folder. I use that quite often for testing purposes, to show variables or messages to see how far a script runs or where an error occurs, as it's also the place where the javascript error-messages are shown.

Greetings,

Stephan
View user's profile Send private message Send e-mail AIM Address ICQ NumberWidgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group