View Full Version : Unicode Action Plugin
Ulrich
06-03-2009, 10:44 PM
Hello,
I had some free time on my hands today, and decided to start coding a new action plugin. Here is the first release, very simple at this point (it may get some enhancements in the future - or not), but I think that it can help in a few cases.
With this free action plugin, you will be able to import any Unicode or UTF-8 encoded text files into a string, which allows you to then process the information further using the Lua scripting engine. At the same time, the plugin allows you to save a string as a new Unicode or UTF-8 encoded text file.
There are currently just two functions:
Unicode.ReadToString(string Filename, string Encoding) and
Unicode.WriteFromString(string Filename, string Text, string Encoding)
Using the plugin, you may be able to read a Unicode text file directly, without having to convert it first with an external program, saving the converted file to disk and finally reading it into AutoPlay Media Studio (or Setup Factory, TrueUpdate or Visual Patch). The Unicode or UTF-8 encoded file will be converted into a ANSI (Latin-1) encoded string. Depending on the feedback, I might be going to add Unicode.ReadToTable(string Filename, string Encoding) and Unicode.WriteFromTable(string Filename, string Text, string Encoding) actions later, so the plugin would work similar to the standard TextFile actions.
Here is the screen from the example project:
http://www.mindquake.com.br/files/ams/SNAG-090604-02.png
The plugin and example project can be downloaded from my AMS page (http://mindquake.com.br/ams.php#plugins).
Ulrich
ShadowUK
06-04-2009, 12:24 AM
Nice one, This is something AMS should have always had.
Friethoe
06-04-2009, 03:30 AM
Thanks, i've waited for this soooooo long, great and thanks again
MicroByte
06-04-2009, 04:15 AM
nice plugin, very useful, thanks :yes
any plan to include a function that can convert a ANSI string to Uni string for sending unicode arguments to dll files?
Imagine Programming
06-04-2009, 04:40 AM
Nice, thanks, I agree with shadow lol
Tomasin
06-04-2009, 07:36 AM
WOW
but, is posible add unicde.FileFind, Unicode.FileDoesExist, Unicode.FolderDoesExist, Unicode.SetLabelText (label, paragraf, button etc), Unicode.ReadINI actions?
Or more better option; Unicode.StringConvert (for example conver one string with one path with one filename in unicode)
Example:
aa = INI.ReadValue(file, section, value (this in unicode or not))
bb = Unicode.StringConvert(aa)
result = Labet.SetText(namelabel, bb)
THANKS
Friethoe
06-04-2009, 08:11 AM
Maybe a stupid question, but would it be possible to use this plug-in with AMS6??
I hope to hear from you :)
Ulrich
06-04-2009, 08:52 AM
Example:
aa = INI.ReadValue(file, section, value (this in unicode or not))
bb = Unicode.StringConvert(aa)
result = Labet.SetText(namelabel, bb)
This will not work. The unicode encoded string can not be passed along to the Lua environment. So, in your example, "aa" would already contain garbage, and there would be no way for Unicode.StringConvert() retrieve the ANSI equivalent of the original text. Instead, the plugin would need to read the INI file by itself, extract and convert the value to ANSI, so you could use it to set the text of the Label.
Maybe a stupid question, but would it be possible to use this plug-in with AMS6??
The plugin should work normally with AutoPlay Media Studio 6.0.
Ulrich
Tomasin
06-04-2009, 12:27 PM
I need find.files in my system, but if the filename contain unicode caracters AMS retuns "????"... and with this FIle.DoesExis not work.
If read one INI file for set text in specific label, button, paragraf, etc and the text contain unicode caracters, AMS not display the text (obvius... xD).
MicroByte
06-04-2009, 02:08 PM
This will not work. The unicode encoded string can not be passed along to the Lua environment. So, in your example, "aa" would already contain garbage, and there would be no way for Unicode.StringConvert() retrieve the ANSI equivalent of the original text. Instead, the plugin would need to read the INI file by itself, extract and convert the value to ANSI, so you could use it to set the text of the Label.
Ulrich
i take it the same goes for the DLL.CallUnicode
i have attempted to write a dll that calls the unicode dll but it dont work unless its compiled with unicode enabled and thats really not much help.
Ulrich
06-04-2009, 02:22 PM
i take it the same goes for the DLL.CallUnicode
i have attempted to write a dll that calls the unicode dll but it dont work unless its compiled with unicode enabled and thats really not much help.
Exactly. As you can't pass a string with Unicode encoding back to Lua, there is no way to use it as an argument for another function, like a call to a dll. I can use UTF-8 and Unicode inside the plugin, but I can't return the string with this encoding back to AMS (it would result in garbage, just like shown in the screen shot of the original post), it must be converted to ANSI first.
For very the same reason, File.DoesExist() is impossible, because if you expect the function to return something, the search criteria (the parameter) would need to be Unicode. And how would you pass the parameter in this encoding when Lua does not support it? So the simple workaround is: do not use Unicode in the filename, or check for the DOS 8.3 equivalent.
Ulrich
Friethoe
06-05-2009, 03:48 AM
I still work with AMS6 and never worked with LUA. It's not available in my setting.
I think I don't use the right terms to find out how to get a lua -plugin into my AMS6.
Could someone guide me how to get things running, because I would really like to use this plugin (lua) with this great convertiontool for my projects.
Information would be very welcome :)
KraMer
06-08-2009, 03:56 AM
This will not work. The unicode encoded string can not be passed along to the Lua environment. So, in your example, "aa" would already contain garbage, and there would be no way for Unicode.StringConvert() retrieve the ANSI equivalent of the original text.
You are mistaken sir. Lua handles strings as a plain char*, a pointer to an array of bytes (be them signed or unsigned doesn't matter in this case). You can easily send UTF-8 through it, though don't exceptany string manipulation to work for anything but ASCII, as AMS assumes ASCII. Since AMS uses the ANSI version of the Windows API you might get a way by converting to the current locale encoding and displaying, and if the text is in that locale boom native language display. To make it work you'd have to either replace the Lua engine or umm... replace the whole AMS API.
Friethoe
06-09-2009, 10:32 AM
I still work with AMS6 and never worked with LUA. It's not available in my setting.
I think I don't use the right terms to find out how to get a lua -plugin into my AMS6.
Could someone guide me how to get things running, because I would really like to use this plugin (lua) with this great convertiontool for my projects.
Information would be very welcome :)
Okay, found it, at last :o
Ulrich, thanks again!
Ulrich
06-17-2009, 12:03 PM
I added two new functions to the plugin, now at version 1.0.2.0:
Unicode.ReadToTable(string Filename, string Encoding) and
Unicode.WriteFromTable(string Filename, table Text, string Encoding).
Ulrich
An extremely useful and code cutting solution. Much appreciated Peter! ;)
Intrigued
07-17-2009, 05:58 PM
Thanks Ulrich!
I'm still around, just in a read mode with AMS of late. I still try to upload all professionally done, polish free plugins, assemblies, etc. So, if someone gets stuck, needs something. Please post it on the forums and one of us archivers will surely try to accomodate.
Ulrich,
Thanks for the suggestion in the other thread about displaying Japanese Character.
Anyways, I searched and found your plugin and it seemed to be my savior. :yes But I kept on getting this 12031 error when I attempted to use it. I double checked the unicode text file and made sure that it is saved in Unicode format. Well, it actually is just a text file with a line of Japanese char created with Notepad. So what could possibly be the cause of this error?
Thanks for your help.
Ulrich
08-24-2009, 10:15 PM
Hello,
could please zip the file and attach it here? The error is expected if the encoding specified does not correspond to the actual source file, or maybe if the source file cannot be translated to the target encoding... I'll have to see what is happening.
Ulrich
Ulrich,
Here you go.
Thanks a lot.
AMSWaves
08-25-2009, 06:39 PM
Hi All,
this is possible to call Unicode Function or pass a string as a PWChar with memory plugin an some api programming.
i write two function (Ansi2Uni & Uni2Ansi) with these you can call unicode functions (Uses Memory Plugin 1.0.2.0)
function Ansi2Uni(st)
blen = (String.Length(st)*2)+2
wbuf = Memory.Allocate(blen)
_st = Memory.Allocate(String.Length(st))
Memory.PutString(_st, st, -1, "UTF8")
DLL.CallFunction("kernel32.dll", "MultiByteToWideChar", "0, 0, ".._st..", -1, "..wbuf..", "..blen, DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL)
Memory.Free(_st)
return wbuf
end
function Uni2Ansi(Uni)
size = DLL.CallFunction("kernel32.dll", "WideCharToMultiByte", "0, 0, "..Uni..", -1, 0, 0, 0, 0", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL)
heap = DLL.CallFunction("kernel32.dll", "GetProcessHeap", "", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL)
ansi = tonumber(DLL.CallFunction("kernel32.dll", "HeapAlloc", heap..", 8, "..size, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL))
DLL.CallFunction("kernel32.dll", "WideCharToMultiByte", "0, 0, "..Uni..", -1, "..ansi..", "..size..", 0, 0", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL)
local ret = Memory.GetString(ansi, -1, "UTF8")
Memory.Free(ansi)
return ret
end
And see example how you can call MessageBoxW(this is not possible in AMS) :
Text = Ansi2Uni("Hello World")
Caption = Ansi2Uni("Test")
DLL.CallFunction("user32.dll", "MessageBoxW", Application.GetWndHandle()..", "..Text..", "..Caption..", 0", DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL)
so i learn one thing in my Programming Life, that nothing is not impossible in programming.
Enjoy.
gvanassche
10-16-2009, 03:08 PM
Ulrich, this really fulfils a need... I'm not sure however it can fulfil my need:
I have text in an RTF file (with Japanese characters) and I want to convert this to a UTF-8 TXT file. Or, I have copied this text from a website, and I want to save the copied japanese UTF-8 text to be save as TXT file in UTF-8.
Would this be possible with your plugin?
(I'm not sure that the clipboard plugin supports UTF-8...)
thanks for your help,
gert
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.