Ed_Maximized Posted October 24, 2006 Posted October 24, 2006 (edited) This little utility reads a txt (or any other text file with anoter extension like au3) and generate the autoit code that incorporate all the text into a variable... Usefull in incorporating text like licenses into the application without using fileinstall Ed (corrected by suggestion of RazerM) expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2+ Author: Edmundo Fasano (Ed_Maximized) edmundofasano@gmail.com Script Function: Convert a text file in a string and generate autoit code Usefull to include long txt files into programs #ce ---------------------------------------------------------------------------- Dim $Text='' $TxtFile=FileOpenDialog('Select a TXT file',@ScriptDir,'All txt files (*.*)') $File = FileOpen($TxtFile, 0) #Region --- CodeWizard generated code Start --- ;InputBox features: Title=Yes, Prompt=Yes, Default Text=Yes If Not IsDeclared("sInputBoxAnswer") Then Dim $sInputBoxAnswer $sInputBoxAnswer = InputBox("Txt2au3","Input a variable name without leading '$'","a"," ","-1","-1","-1","-1") Select Case @Error = 0 ;OK - The string returned is valid $var='$'&$sInputBoxAnswer Case @Error = 1 ;The Cancel button was pushed Exit Case @Error = 3 ;The InputBox failed to open Exit EndSelect #EndRegion --- CodeWizard generated code End --- $Main = GUICreate('Txt2Au3 - '&$TxtFile, 500, 380) $Edit = GUICtrlCreateEdit('', 0, 0, 500, 380) GUISetState() $Text="#region ;generated by Txt2au3 - code by Ed_maximized"&@CRLF&$var&'=""'&@CRLF ; Check if file opened for reading OK If $File = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $Line = FileReadLine($File) If @error = -1 Then ExitLoop $Line = _ReplaceSingleQuotes($Line) $Text &= $var&' &="' & $Line&'"&@CRLF'&@CRLF ConsoleWrite($line) Wend FileClose($File) $Text &= 'MsgBox(0,"Test MsgBox",'&$var&') ;test line you can comment this'&@CRLF $Text &= '#endregion' GUICtrlSetData($Edit,$Text) While 1 Switch GUIGetMsg() Case - 3 Exit EndSwitch WEnd Func _ReplaceSingleQuotes($Line) Dim $i,$j,$k="" For $i=1 To StringLen($line) Switch StringMid($line,$i,1) Case Chr(34) $k &= Chr(34)&Chr(34) Case Else $k &= StringMid($line,$i,1) EndSwitch Next Return $k EndFunc Edited October 25, 2006 by Ed_Maximized ShapedGUI Creator : Shaped gui the easy way!!!Txt2au3 : the easy way to include text files into your program without fileinstall_GUICreateWithTiledBackground : Put a GIF in the background of your formsSQLite Database BrowserAnimated GIF UDF : Put animations in your GUI's
RazerM Posted October 25, 2006 Posted October 25, 2006 I like the concept, however _ReplaceSingleQuotes can be changed to this: Func _ReplaceQuotes($Line) Dim $i,$j,$k="" For $i=1 To StringLen($line) Switch StringMid($line,$i,1) Case Chr(34) $k &= Chr(34)&Chr(34) Case Else $k &= StringMid($line,$i,1) EndSwitch Next Return $k EndFunc Because only double quotes need to be doubled up, try this text file in the original then in mine: single ' double " My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Ed_Maximized Posted October 25, 2006 Author Posted October 25, 2006 I like the concept, however _ReplaceSingleQuotes can be changed to this: Func _ReplaceQuotes($Line) Dim $i,$j,$k="" For $i=1 To StringLen($line) Switch StringMid($line,$i,1) Case Chr(34) $k &= Chr(34)&Chr(34) Case Else $k &= StringMid($line,$i,1) EndSwitch Next Return $k EndFunc Because only double quotes need to be doubled up, try this text file in the original then in mine: single ' double " Done! Thanks Ed ShapedGUI Creator : Shaped gui the easy way!!!Txt2au3 : the easy way to include text files into your program without fileinstall_GUICreateWithTiledBackground : Put a GIF in the background of your formsSQLite Database BrowserAnimated GIF UDF : Put animations in your GUI's
AZJIO Posted August 1, 2010 Posted August 1, 2010 (edited) Fixed an issue limit of 4085 expandcollapse popup; @AZJIO ; обновления: добавлена защита от размера переменной более 4085 симолов, скорректированы переходы строк, замена апострофа ' в тексте двойным апострофом. Теперь результат является точной копией исходника. ; В эту версию добавлена ком-строка для работы с Notepad++. Выделенный текст легко передаётся скрипту в качестве ком-строки. Если возникнет проблема, то копируем его в буфер обмена и ничего не выделяя выполняем горячую клавишу назначенную скрипту в Notepad++, при этом в буфере происходит замена текста и можно ставлять его в окно редактора Notepad++ или SciTE. ;Правильная команда для Notepad++ все пути и "$(CURRENT_WORD)" обрамляются кавычками, иначе параметр воспринимается как множество параметров. ;"C:\Program Files\AutoIt3AutoIt3.exe" "C:\Program Files\AutoIt3\txt2au3.au3" "$(CURRENT_WORD)" #NoTrayIcon $bufer_read=1 ; 1 ClipGet, 0 - FileOpenDialog $bufer_write=1 ; 1 ClipPut, 0 - FileWrite - file_0.au3 $Msg_FW = 0 ; 1 - out FileWrite, если 0 - out Msg If $CmdLine[0]<>0 And $CmdLine[1]<>'' Then $text=$CmdLine[1] Else If $bufer_read=1 Then $text = ClipGet() Else $Path = FileOpenDialog("Выбор файла.", @WorkingDir & "", "Скрипт (*.*)", 1 + 4 ) If @error Then Exit $file = FileOpen($Path, 0) $text= FileRead($file) FileClose($file) EndIf EndIf ;============================== ; UDF File.au3 If StringInStr($text, @LF) Then $aFiletext = StringSplit(StringStripCR($text), @LF) ElseIf StringInStr($text, @CR) Then $aFiletext = StringSplit($text, @CR) Else If StringLen($text) Then Dim $aFiletext[2] = [1, $text] Else MsgBox(0, "Сообщение", "нет данных") Exit EndIf EndIf ; preparing the variable $text ; подготовка переменной $text $text='$text= _'&@CRLF $Kol2='' $ostatok='' $Kol3='' $Kol4=0 $trkol=0 $trkol2=0 ; quota 4085, but better a little less, since in объеденяющей variable not more than 4084 ($text&=) ; лимит 4085, но лучше чуть меньше, так как в объеденяющей переменной не более 4084 ($text&=) $Limit=4070 For $i = 1 to UBound($aFiletext) - 1 $aFiletext[$i]= StringReplace($aFiletext[$i], "'", "''") ; if in line more than 4084 symbols, that separate line on uniting variable ($text&=) ; если в строке более 4084 символа, то разделить строку на объединяющие переменные ($text&=) If StringLen($aFiletext[$i]) > $Limit Then $trkol=1 $trkol2=1 $text=StringTrimRight($text,6)&@CRLF $Kol2=StringLen($aFiletext[$i]) $Kol4+=$Kol2 $ostatok=Mod($Kol2,$Limit) $Kol3=int($Kol2/$Limit) If $ostatok <> 0 Then $Kol3+=1 For $z = 1 to $Kol3 If $z = $Kol3 Then $text&='$text&= '&'"'&StringMid($aFiletext[$i], 1)&'" & @CRLF & _'&@CRLF Else $text&='$text&= '&'"'&StringMid($aFiletext[$i], 1,$Limit)&'"'&@CRLF $aFiletext[$i]=StringTrimLeft($aFiletext[$i],$Limit) EndIf Next EndIf If $trkol2=1 Then $trkol2=0 ContinueLoop EndIf ; if in amount of the short lines more than 4084 symbols, that separate the line on uniting variable ($text&=), in this instance insert the separator. ; as well as if has operated previous area "line more than 4084 symbols" ; если в сумме коротких строк более 4084 символа, то разделить строку на объединяющие переменные ($text&=), в данном случае вставляем разделитель. ; а также если сработал предыдущий участок "строка более 4084 символа" If StringLen($text) > $Limit+$Kol4 Or $trkol=1 Then $trkol=0 $text=StringTrimRight($text,6)&@CRLF&'$text&= _'&@CRLF $Kol4=StringLen($text) EndIf If $aFiletext[$i]='' Then $text&='@CRLF & _'&@CRLF Else $text&=''''&$aFiletext[$i]&''' & @CRLF & _'&@CRLF EndIf Next $text=StringTrimRight($text,14) ; if text at the end with turning the lines, that additional removing 3 symbol ; если текст в конце с переходами строк, то дополнительная подрезка 3-х симовлов If StringRight($text,3)=' & ' Then $text=StringTrimRight($text,3) If $Msg_FW = 0 Then $text&=@CRLF&'MsgBox(0, "Сообщение", $text)' Else $text&=@CRLF&'$file = FileOpen(@ScriptDir&"\file.txt",2)'&@CRLF&'FileWrite($file, $text)'&@CRLF&'FileClose($file)' EndIf ;============================== If $bufer_write=1 Then ClipPut ( $text ) Else $filetxt=@ScriptDir&'\file_' $i = 0 While FileExists($filetxt&$i&'.au3') $i = $i + 1 WEnd $filetxt=$filetxt&$i&'.au3' $file = FileOpen($filetxt ,2) FileWrite($file, $text) FileClose($file) EndIf Edited August 1, 2010 by AZJIO My other projects or all
AZJIO Posted August 1, 2010 Posted August 1, 2010 File 2 Au3 (txt, dll, exe, gif, all) expandcollapse popup; @AZJIO #NoTrayIcon $Gui = GUICreate("File2Au3.au3", 300, 94, -1, -1, -1, 0x00000010) $Input1 = GUICtrlCreateLabel('', 0, 0, 300, 94) GUICtrlSetState(-1, 136) GUICtrlCreateLabel ("Throw here a file for converting in a script", 10,2,280,17) $StatusBar=GUICtrlCreateLabel (@CRLF&@CRLF&'StatusBar', 10,23,280,57) GUISetState () While 1 $msg = GUIGetMsg() Select Case $msg = -13 $filename=StringRegExp(@GUI_DRAGFILE,'(^.*)\\(.*)\.(.*)$',3) GUICtrlSetData($StatusBar, 'File '&$filename[1]&'.'&$filename[2]&' is accepted'&@CRLF&'Read...') $ScrBin='$sData = ''0x'''&@CRLF $file = FileOpen(@GUI_DRAGFILE, 16) While 1 $Bin = FileRead($file, 2040) If @error = -1 Then ExitLoop $ScrBin&='$sData &= '''&StringTrimLeft($Bin,2)&''''&@CRLF Sleep(1) WEnd FileClose($file) GUICtrlSetData($StatusBar, 'File '&$filename[1]&'.'&$filename[2]&' is accepted'&@CRLF&'Write...') $Output = $filename[0]& '\Bin_' $i = 1 While FileExists($Output & $i & '_'&$filename[1]&'.au3') $i += 1 WEnd $Output = $Output & $i & '_'&$filename[1]&'.au3' $file = FileOpen($Output,2) FileWrite($file, $ScrBin&@CRLF& _ '$sData=Binary($sData)'&@CRLF& _ '$file = FileOpen(@ScriptDir&''\Copy_'&$filename[1]&'.'&$filename[2]&''',18)'&@CRLF& _ 'FileWrite($file, $sData)'&@CRLF& _ 'FileClose($file)') FileClose($file) GUICtrlSetData($StatusBar, 'File '&$filename[1]&'.'&$filename[2]&' is accepted'&@CRLF&'Script-File Bin_'& $i & '_'&$filename[1]&'.au3 is created.') Case $msg = -3 Exit EndSelect WEnd My other projects or all
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now