Author Topic: ASCII control character(s?) break profile import  (Read 3860 times)

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
ASCII control character(s?) break profile import
« on: October 18, 2019, 03:38:47 PM »
So I have this string i need to split at the START TEXT control character (ASCII 0x02). I also want to distribute the profile to other people.

Now, while everything works just fine in general, having people import the profile leads to an error: the importer doesn’t like the 0x02 character.

https://github.com/alterNERDtive/VoiceAttack-profiles/raw/devel/profiles/RatAttack-Profile.vap

Try importing this one (attached here, too).

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2825
Re: ASCII control character(s?) break profile import
« Reply #1 on: October 18, 2019, 06:10:56 PM »
Was the profile modified using a text editor?

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: ASCII control character(s?) break profile import
« Reply #2 on: October 18, 2019, 07:41:39 PM »
No. Just exported.

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: ASCII control character(s?) break profile import
« Reply #3 on: October 18, 2019, 07:43:13 PM »
Maybe I should clarify that I’m splitting a string in a VoiceAttack command. I have it in the clipboard, then run a VoiceAttack command. The info I need is delimited by said 0x02 character; VA accepted it as a variable value with 0 problems. Exporting works too, just importing it again (same machine or others) errors out.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2825
Re: ASCII control character(s?) break profile import
« Reply #4 on: October 18, 2019, 10:56:30 PM »
Hmmm...  The problem is that  0x02 is not a valid character in XML.  Not sure how it's getting handled outbound, but it is definitely breaking when deserializing.  I would need to write code around how VA exports and then imports its data around the use of that character.  This isn't going to happen any time soon, as I'm focusing on UI improvements for the time being.  Are there any other characters you can use as string delimiters?  Also, have you tried exporting as binary and not xml?  This would be the, 'VoiceAttack Compressed Profile' option when exporting - it's possible that it may be a little more forgiving.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: ASCII control character(s?) break profile import
« Reply #5 on: October 19, 2019, 03:25:54 AM »
Alternatively you could use an inline function to convert the keycode to the ASCII character you need at runtime (replacing the "Set a Text Value" action you're using now), meaning it will be stored in the profile database as normal ASCII characters (I.E. "0", "x" and "2") that can be exported to XML without issue:
Code: [Select]
public class VAInline
{
public void main()
{
VA.SetText("~delimiter", ((char)0x02).ToString());
}
}

I used the hexadecimal identifier in this case because I feel it's easier to read and understand what the function will do, however you could also use the decimal identifier if you prefer:
Code: [Select]
public class VAInline
{
public void main()
{
VA.SetText("~delimiter", ((char)2).ToString());
}
}

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: ASCII control character(s?) break profile import
« Reply #6 on: October 19, 2019, 10:13:47 AM »
Thanks, that’s a practical approach I guess. Will try and report back.

Is inline code exported just fine with the profile or do I have to jump through extra hoops there?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: ASCII control character(s?) break profile import
« Reply #7 on: October 19, 2019, 10:17:11 AM »
Inline functions are exported and imported like any other action. As long as you don't embed special characters in the source code that can't be (de)serialized it should work.

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: ASCII control character(s?) break profile import
« Reply #8 on: October 19, 2019, 04:21:24 PM »
So while this is kind of ugly IMO it works fine, thanks again.

I still think it’s a bug in VA and should be fixed :)

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2825
Re: ASCII control character(s?) break profile import
« Reply #9 on: October 19, 2019, 04:37:56 PM »
Definitely a bug - an edge case, but still a bug. 

Have you tried exporting as a binary (compressed VAP) at all?  Curious if that solves the issue for now.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: ASCII control character(s?) break profile import
« Reply #10 on: October 19, 2019, 04:58:44 PM »
Binary .vap imports fine with that character (and preserves it correctly; I checked).

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: ASCII control character(s?) break profile import
« Reply #11 on: October 19, 2019, 11:02:45 PM »
Have you tried exporting as a binary (compressed VAP) at all?

Hah, I didn’t even know that was a thing :D

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2825
Re: ASCII control character(s?) break profile import
« Reply #12 on: October 20, 2019, 02:28:56 AM »
Quote
Hmmm...  The problem is that  0x02 is not a valid character in XML.  Not sure how it's getting handled outbound, but it is definitely breaking when deserializing.  I would need to write code around how VA exports and then imports its data around the use of that character.  This isn't going to happen any time soon, as I'm focusing on UI improvements for the time being.  Are there any other characters you can use as string delimiters?  Also, have you tried exporting as binary and not xml?  This would be the, 'VoiceAttack Compressed Profile' option when exporting - it's possible that it may be a little more forgiving.

Quote
Also, have you tried exporting as binary and not xml?  This would be the, 'VoiceAttack Compressed Profile' option when exporting - it's possible that it may be a little more forgiving.

This would be the fastest route.