Files are downloaded to, in default, x:/downloads folder where x is the last hard drive in the system, so which is not fixed.
The download path setting is written in the xml file look like this:
{persist_settings}
{download}
{download_directory}{![CDATA[X:\downloads\]]}{/download_directory}
({ and } should be respectively. But I do not know how to make it correctly show in the post. Sorry about that.)
How can I write this xml file to change the path to App/data folder in the portable app? or how can I move the x:/downloads folder to app/data folder?
Thanks.
The first, and easier of your two problems is that you use < and > for the brackets.
The second is a little more complex. If you go to the FileWriteN section of the reference, you'll see that you have three options working with XML, namely XML attribute, XML text, and Replace. If you know your stuff in XML, then one of the first two is undoubtedly more powerful. Otherwise, using Replace should be more than enough.
Sample code is as follows (using your post for details):
The above code will replace the default download directory (assuming it is "X:\downloads") with Data\downloads and then update the location each time it is run after that to make sure it always points to the right drive and folder. Hope this helps!
Thank you for your reply. But the problem is that we do not know the drive letter which depend on the system when the app first run. (I assume the app will be pass to someone.)
You need to do something a little tricky:
1) Place a copy of the most basic version of the config file in the relatively correct place in App\DefaultData (eg. If config file is usually at Data\config.xml, place a basic first-run copy of it at App\DefaultData\config.xml)
2) Replace the path (or part of the path) created in the DefaultData\ copy with
DEFAULTFILESDIR
or something similarly unique3) With a slight modification of darksabre76's code above:
[FileWrite1]
Type=Replace
File=%PAL:DataDir%\config.xml
Find=X:\downloads
Replace=%PAL:DataDir%\downloads
[FileWrite2]
Type=Replace
File=%PAL:DataDir%\config.xml
Find=%PAL:LastDrive%%PAL:LastPackagePartialDir%\
Replace=%PAL:Drive%%PAL:PackagePartialDir%\
[FileWrite3]
Type=Replace
File=%PAL:DataDir%\config.xml
Find=%PAL:LastPortableAppsBaseDir%\
Replace=%PAL:PortableAppsBaseDir%\
[FileWrite4]
Type=Replace
File=%PAL:DataDir%\config.xml
Find=%PAL:LastDrive%\
Replace=%PAL:Drive%\
[FileWrite5]
Type=Replace
File=%PAL:DataDir%\config.xml
Find=DEFAULTFILESDIR
Replace=%PAL:DataDir%\downloads
This will mean that when the program is run for the very first time it will copy config.xml from DefaultData to Data, then change DEFAULTFILESDIR to point to where you want it.
Also, for posting html/xml-like code you can type < for < and > for >.
Problem solved. Thank you.
btw I like to make a request to the development team of PAL to
add the ability to change/write string between 2 defind strings.
You could also do it with a [FileWrite] with
Type=XML text
with which you could directly target the <download_directory> node (although you would have to ensure to handle the <![CDATA[]]> within the value you were writing).It could also (as long as the tag was unique within the file) be done with a
Type=ConfigWrite
.The only reason I (and I assume darksabre76, too) did it this way is that is the way we are more comfortable using FileWrites.
My suggestion is in fact want to extend the ability of Replace function in [FileWriteN] which must know exactly the string to be replaced.
Another reason is that it is easier to learn/write than XML attribute/text for beginner learner like me still do not fully understand what is a node.
If you're wanting the value to always be a subdirectory of AppName/Data, you can do it easily with FileWriteN using XML text:
[EDIT] Note that if there's more to the XML file, your XPath may be more extensive.