AutoHotkey Community

It is currently May 27th, 2012, 9:20 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: December 23rd, 2011, 11:38 pm 
Offline

Joined: October 13th, 2009, 11:56 am
Posts: 102
As far as I understood from another topic I've created - currently there are no ways to write a script that would store it's setting not in an external file (like *.ini), but inside the script's file itself: in the *.exe

What is so impossible in such a thing? Why can't an exe be regarded as an archive with a special free space left for storing settings?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 23rd, 2011, 11:59 pm 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
It's just impractical and there aren't many reasons to do it.
In general this is possible of course, but it's not going to be easy. Using config files is much more reasonable.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 24th, 2011, 12:07 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
Can anyone provide an example of a commercial or popular application that does this?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 24th, 2011, 12:35 am 
Offline

Joined: June 4th, 2010, 9:04 pm
Posts: 1347
Location: california
Since a script file is just essentially a text file that gets run when you click on it or "reload" it, yes it's possible to store configuration information in the file. The tricky part is in deciding where in the file you want to save the data. And a lot depends on how much data you need in the script and when you need it.

See you're not just dealing with data in your script file you're also dealing with comments, code sections, hotkeys, hotstrings and such that could/might get trashed with an improper write to the base script file. So then you'd need to save a working copy of the script file so you could undo any mess you might have for an ill-behaved write.

If you store the data at the end you need some way to distinguish where "the end" of the script actually is. Append the data there and reload your script. Also you need to figure out how to avoid duplicate or conflicting entries. In effect you are using an external file to store the data since you have to write to the script file. But now you have the added disadvantage that you must stop or reload a running script to reload any changed data. Why make it hard on yourself? Use a text file or an ini file to save what needs saving. If you set up ini or text read and write routines in your script, you can reload the data on the fly without exiting your running code. You'd have to write those routines anyway to write to your script file.

One other important point, it is considered poor programming practice to modify scripts or programs on the fly during a production run of the program. It leads to some serious maintainence issues if a write goes bad due to timing or lag or even a memory glitch and then not just the data is corrupt but the primary program as well.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 24th, 2011, 9:47 am 
Offline

Joined: October 13th, 2009, 11:56 am
Posts: 102
girlgamer,
thank you for such pretty detailed explanation.
I just think it still will be useful for small scripts that do one action and just let user choose a hotkey for that action. They need to store the user defined hotkey somewhere and for more portability - it would be way better to not use any external files, in my opinion.
In this particular case - I think it's pretty possible to define the maximum length of the space needed to store such data.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 24th, 2011, 3:34 pm 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
That's what folders are used for ;)
Just copy the folder instead of the single script file.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 24th, 2011, 5:50 pm 
Offline

Joined: October 13th, 2009, 11:56 am
Posts: 102
fragman wrote:
That's what folders are used for ;)
Just copy the folder instead of the single script file.

I have a single folder where I keep all portable utils (and most of them do not use external files to store anything). Each of them is accessible from that folder with a double click and when you want to run one and than another util - you do not have to go up/down from/to parental_folders/subfolders.
You suggest me to make this folder consist of sub-folders with utils.
Then every util stored there - wouldn't be that easily accessible and a simple task to execute 5 utils would require me way more clicks, than just 5x2.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 24th, 2011, 6:06 pm 
Write a launcher script ;-)
(or use one of the many around on the forum)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 24th, 2011, 7:53 pm 
Offline

Joined: June 4th, 2010, 9:04 pm
Posts: 1347
Location: california
That's how i do mine too a single folder with all my scripts. it's called my scripts directory but I also have a folder that holds all my script revisions -- a repository of files as it were -- that i can revert back to in case a specific change to one of my scripts doesn't work out. And many of mine use .txt files or .ini files that contain configuration data. Each of the apps that needs configuration have, built in, a method for creating a default configuration file if the script detects the config doesn't exist. I also build in to those same scripts a way for the user to modify the configuration settings so they can personalize the way the scripts work. It needn't be a big thing to use ini or config files. Many programs use them.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 24th, 2011, 8:38 pm 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
I use .lnk files :?

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 24th, 2011, 8:48 pm 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3330
Location: Simi Valley, CA
This wish has already been granted: RegWrite OR NTFS file streams.

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 24th, 2011, 9:55 pm 
Offline

Joined: June 4th, 2010, 9:04 pm
Posts: 1347
Location: california
Great idea vxe. I'm glad you posted that. Something new to play with.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 25th, 2011, 6:01 pm 
iDrug wrote:
(and most of them do not use external files to store anything).


They probably don't need to store anything, if they do maybe they don't care if settings are reset when the .exe is moved. Most "utils" are small apps which are not so much portable as just not needing to be installed.

I don't see what's so painful about another file in the same folder. If the user is too dumb to move or copy both when they're being "portable" then they shouldn't be in charge of such things to start with. You can always give the user a choice of how and where to store settings.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 25th, 2011, 11:54 pm 
Not pretty but a workable concept:
http://www.autohotkey.com/forum/topic80378.html
(you include the source + ahk2exe + autohotkeysc.bin, fileinstall those, write a batch file, exit executable, delete it, have the batch file recompile the script with the modifications)


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group