Script's Encode to Unicode(UTF-16) converter

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
Location: Seoul
Contact:

Script's Encode to Unicode(UTF-16) converter

09 Jan 2015, 23:04

Image

I write korean in my script since I'm Korean (and sorry for my bad english)

as a result, .ahk script files have to saved in UTF-16 encode or else my script gonna show me a bunch of crack letters..
I have to change script's encode manually which is very very tired.

So I came up with this, it change all scipt's encode to Unicode!

supports Drag&Drop, and loading all .ahk files to listview and much more
I assume only a few people will feel interest on this since English user doesnt need this..
but.. hope this will be a good example of using listview for beginners!

Code: Select all

;/ Scirpt to Unicode by Soft

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
#SingleInstance force
Menu, Tray, NoStandard
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

nb = 1
MsgBox, 4160, Notice, should run on the .ahk directory!
Gui, add, edit, xm+420 ym w400 h260 vStrIn, Encoded soruce code`n`nyou can drag&drop a script
;Gui, add, edit, xm y+30 w500 h200 vStrOut, Changed
Gui, add, ListView, xm ym w400 h260 vmyListView gAHKlist AltSubmit, Name|Path
Gui, add, button, xm+420 ym+265 w100 h30, SingleEncode
Gui, add, button, xm ym+265 w100 h30 gAHKget, load script
Gui, add, button, xm+120 ym+265 w100 h30, EncodeAll
LV_ModifyCol(1, 150)
LV_ModifyCol(2, 230)
Gui, show, Autosize, Script to Unicode(UTF-16)
return

AHKget:
LV_DELETE() 
Loop, %A_ScriptDir%\*.ahk
{
	Howmuch := A_Index
	File%A_Index% := A_LoopFileName
	LV_Add("", A_LoopFileName, A_LoopFileDir)
}
Gui, +OwnDialogs
MsgBox, 4160, , % Howmuch "`rscripts loaded!"
return

AHKlist:
Gui,Submit,NoHide
if (lv_getcount() > 0)
{
if A_GuiEvent = DoubleClick
{
	StrIn := ""
	GuiControl,, StrIn, 
	LV_GetText(ThisName, A_EventInfo, 1)
	FileRead, Opt2, %ThisName%
	GuiControl,, StrIn, %Opt2%
}
}
return

ButtonEncodeAll:
Gui, +OwnDialogs
MsgBox, 33, Check, Change all script's encoding?
IfMsgBox, Ok
{
Gui,Submit,NoHide
while nb <= LV_GetCount()
{
	StrIn := ""
	GuiControl,, StrIn, 
	LV_GetText(TrueName, A_Index)
	FileRead, Opt2, %TrueName%
	GuiControl,, StrIn, %Opt2%
	FileDelete, %TrueName%
	FileAppend, %Opt2%, %TrueName%, UTF-16
	;MsgBox % TrueName "Finish"
	nb ++
	TrayTip,, % TrueName "Finished"
}
nb := 1
}
return

ButtonSingleEncode:
Gui, Submit, NoHide
FileDelete, %FileName%
StringReplace, op1, FileName, %A_ScriptDir%\,, All
FileAppend, %StrIn%, %op1%, UTF-16
return

GuiDropFiles:
FileEncoding, UTF-8
StrIn := ""
GuiControl,, Strin, 
if A_GuiControl = StrIn
{
	FileName := A_GuiEvent
	FileRead, Draged, %A_GuiEvent%
	GuiControl,, StrIn, %Draged%
}
return

GuiClose:
ExitApp
AutoHotkey & AutoHotkey_H v1.1.22.07
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: Script's Encode to Unicode(UTF-16) converter

10 Jan 2015, 21:54

as a result, .ahk script files have to saved in UTF-16 encode or else my script gonna show me a bunch of crack letters..
UTF-8 is the recommended encoding. It will work just as well as UTF-16, but the files will be smaller. Either way, each file must begin with a (UTF-8 or UTF-16) byte order mark.
User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
Location: Seoul
Contact:

Re: Script's Encode to Unicode(UTF-16) converter

11 Jan 2015, 01:15

lexikos wrote:
as a result, .ahk script files have to saved in UTF-16 encode or else my script gonna show me a bunch of crack letters..
UTF-8 is the recommended encoding. It will work just as well as UTF-16, but the files will be smaller. Either way, each file must begin with a (UTF-8 or UTF-16) byte order mark.
oh I didnt know that, it could encoded in UTF-8 too
thanks lex
AutoHotkey & AutoHotkey_H v1.1.22.07

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 257 guests