You are here

xml write

8 posts / 0 new
Last post
JLim
Offline
Last seen: 1 month 4 days ago
Joined: 2013-07-17 01:30
xml write

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.

darksabre76
darksabre76's picture
Offline
Last seen: 1 year 8 months ago
Developer
Joined: 2011-04-19 23:28
Try this

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):

[FileWrite1]
Type=Replace
File=%PAL:AppDir%\AppName\sample.xml
Find=X:\downloads
Replace=%PAL:DataDir%\downloads

[FileWrite2]
Type=Replace
File=%PAL:AppDir%\AppName\sample.xml
Find=%PAL:LastPackagePartialDir%
Replace=%PAL:PackagePartialDir%

[FileWrite3]
Type=Replace
File=%PAL:AppDir%\AppName\sample.xml
Find=%PAL:LastDrive%
Replace=%PAL:Drive%

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!

JLim
Offline
Last seen: 1 month 4 days ago
Joined: 2013-07-17 01:30
Thank you for your reply. But

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.)

Ken Herbert
Ken Herbert's picture
Online
Last seen: 7 min 8 sec ago
DeveloperModerator
Joined: 2010-05-25 18:19
For first run path detection

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 unique

3) 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 &lt; for < and &gt; for >.

JLim
Offline
Last seen: 1 month 4 days ago
Joined: 2013-07-17 01:30
Problem solved. Thank

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.

Ken Herbert
Ken Herbert's picture
Online
Last seen: 7 min 8 sec ago
DeveloperModerator
Joined: 2010-05-25 18:19
Not really necessary

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.

JLim
Offline
Last seen: 1 month 4 days ago
Joined: 2013-07-17 01:30
My suggestion is in fact want

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.

Gord Caswell
Gord Caswell's picture
Offline
Last seen: 1 day 5 hours ago
DeveloperModerator
Joined: 2008-07-24 18:46
Always DataDir?

If you're wanting the value to always be a subdirectory of AppName/Data, you can do it easily with FileWriteN using XML text:

[FileWriteN]
Type=XML text
File=%PAL:DataDir%\settings.xml
XPath=/persist_settings/download/download_directory
Value=<![CDATA[%PAL:DataDir%\downloads\]]>

[EDIT] Note that if there's more to the XML file, your XPath may be more extensive.

Log in or register to post comments