Jump to content

Restore SourceCode Function


Recommended Posts

Hi,

I created this to have an easy possibility to restore my sources, but I guess it is a bit too complicated. :)

Can you show me an better / easier way?

Put this in your SciteUser.properties

# 37 Restore SourceCode
command.37.*.au3="$(autoit3dir)\beta\autoit3.exe" "$(SciteDefaultHome)\PUT HERE THE PATH TO THE SCRIPT!!!" "$(FilePath)"
command.name.37.*.au3=SourceCode
command.save.before.37.*.au3=1
command.is.filter.37.*.au3=1
command.shortcut.37.*.au3=Ctrl+Shift+Alt+O

#include<GUIConstants.au3>
; Get SciTE DirectorHandle
Global $GUI = GUICreate('SourceCode')
Global $SciTECmd, $My_Dec_Hwnd, $Scite_hwnd
Global $Scite_hwnd = WinGetHandle("DirectorExtension")
GUIRegisterMsg($WM_COPYDATA, "MY_WM_COPYDATA")
Global $My_Dec_Hwnd = Dec(StringTrimLeft($GUI, 2))

_restoreSourceCode("Mega.exe", 'Autoit')

Func _restoreSourceCode($scriptName = 'source.exe', $passphrase = '')
    If Not ProcessExists('SciTE.exe') Then Exit (0)
    Local $opt = Opt('WinTitleMatchMode', 4)
    SendSciTE_Command($My_Dec_Hwnd, $Scite_hwnd, "askfilename:")
    $SciTECmd = StringReplace($SciTECmd, '\\', '\')
    $FilePath = StringTrimLeft($SciTECmd, StringInStr($SciTECmd, ':', Default, 3))
    Opt('WinTitleMatchMode', $opt)
    SendSciTE_Command($My_Dec_Hwnd, $Scite_hwnd, "menucommand:106")
    FileCopy($FilePath, 'c:\TEMP\SourceCode.au3', 1)
    $h_file = FileOpen($FilePath, 1)
    If $h_file = -1 Then
        SendSciTE_Command($My_Dec_Hwnd, $Scite_hwnd, "output:+> Error open file:  " & $FilePath)
        Exit
    EndIf
    SendSciTE_Command($My_Dec_Hwnd, $Scite_hwnd, "menucommand:106")
    Sleep(1000)
    FileWrite($h_file, FileRead($h_file) & @CRLF)
    FileWrite($h_file, "; ************************************************************************************" & @CRLF)
    FileWrite($h_file, "; SourceCode restore function " & @CRLF)
    FileWrite($h_file, "_restoreSourceCode()" & @CRLF & @CRLF)
    FileWrite($h_file, "Func _restoreSourceCode() " & @CRLF)
    FileWrite($h_file, @TAB & "Local  $passphrase = '" & $passphrase & "'" & @CRLF)
    FileWrite($h_file, @TAB & "If @Compiled And @ScriptName == " & "'" & $scriptName & "'" & " Then " & @CRLF)
    FileWrite($h_file, @TAB & @TAB & "If $passphrase <> '' Then  " & @CRLF)
    FileWrite($h_file, @TAB & @TAB & @TAB & "Local $re = InputBox('SourceCode recovery', 'Please, type in the password : ', '')" & @CRLF)
    FileWrite($h_file, @TAB & @TAB & @TAB & "If $re == '" & $passphrase & "'Then " & @CRLF)
    FileWrite($h_file, @TAB & @TAB & @TAB & @TAB & "FileInstall('C:\TEMP\SourceCode.au3', @DesktopDir &'\SourceCode.au3', 1)" & @CRLF)
    FileWrite($h_file, @TAB & @TAB & @TAB & @TAB & "MsgBox(64, 'Information', 'SourceCode restored!', 5)" & @CRLF)
    FileWrite($h_file, @TAB & @TAB & @TAB & "Else" & @CRLF)
    FileWrite($h_file, @TAB & @TAB & @TAB & @TAB & "MsgBox(16, 'Error', 'Wrong password!', 5)" & @CRLF)
    FileWrite($h_file, @TAB & @TAB & @TAB & "EndIf" & @CRLF)
    FileWrite($h_file, @TAB & @TAB & "EndIf" & @CRLF)
    FileWrite($h_file, @TAB & "EndIf" & @CRLF)
    FileWrite($h_file, "EndFunc" & @CRLF)
    FileWrite($h_file, "; ************************************************************************************")
    FileClose($h_file)
EndFunc   ;==>_restoreSourceCode

; Send command to SciTE
Func SendSciTE_Command($My_Hwnd, $Scite_hwnd, $sCmd)
    $sCmd = ":" & $My_Dec_Hwnd & ":" & $sCmd
    Local $CmdStruct = DllStructCreate('Char[' & StringLen($sCmd) + 1 & ']')
    DllStructSetData($CmdStruct, 1, $sCmd)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr')
    DllStructSetData($COPYDATA, 1, 1)
    DllStructSetData($COPYDATA, 2, StringLen($sCmd) + 1)
    DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct))
    DllCall('User32.dll', 'None', 'SendMessage', 'HWnd', $Scite_hwnd, _
            'Int', $WM_COPYDATA, 'HWnd', $My_Hwnd, _
            'Ptr', DllStructGetPtr($COPYDATA))
EndFunc   ;==>SendSciTE_Command

; Received Data from SciTE
Func MY_WM_COPYDATA($hWnd, $msg, $wParam, $lParam)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr', $lParam)
    $SciTECmdLen = DllStructGetData($COPYDATA, 2)
    Local $CmdStruct = DllStructCreate('Char[255]', DllStructGetData($COPYDATA, 3))
    $SciTECmd = StringLeft(DllStructGetData($CmdStruct, 1), $SciTECmdLen)
EndFunc   ;==>MY_WM_COPYDATA

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

I created this to have an easy possibility to restore my sources, but I guess it is a bit too complicated. :)

Can you show me an better / easier way?

Put this in your SciteUser.properties

# 37 Restore SourceCode
command.37.*.au3="$(autoit3dir)\beta\autoit3.exe" "$(SciteDefaultHome)\PUT HERE THE PATH TO THE SCRIPT!!!" "$(FilePath)"
command.name.37.*.au3=SourceCode
command.save.before.37.*.au3=1
command.is.filter.37.*.au3=1
command.shortcut.37.*.au3=Ctrl+Shift+Alt+O

#include<GUIConstants.au3>
; Get SciTE DirectorHandle
Global $GUI = GUICreate('SourceCode')
Global $SciTECmd, $My_Dec_Hwnd, $Scite_hwnd
Global $Scite_hwnd = WinGetHandle("DirectorExtension")
GUIRegisterMsg($WM_COPYDATA, "MY_WM_COPYDATA")
Global $My_Dec_Hwnd = Dec(StringTrimLeft($GUI, 2))

_restoreSourceCode("Mega.exe", 'Autoit')

Func _restoreSourceCode($scriptName = 'source.exe', $passphrase = '')
    If Not ProcessExists('SciTE.exe') Then Exit (0)
    Local $opt = Opt('WinTitleMatchMode', 4)
    SendSciTE_Command($My_Dec_Hwnd, $Scite_hwnd, "askfilename:")
    $SciTECmd = StringReplace($SciTECmd, '\\', '\')
    $FilePath = StringTrimLeft($SciTECmd, StringInStr($SciTECmd, ':', Default, 3))
    Opt('WinTitleMatchMode', $opt)
    SendSciTE_Command($My_Dec_Hwnd, $Scite_hwnd, "menucommand:106")
    FileCopy($FilePath, 'c:\TEMP\SourceCode.au3', 1)
    $h_file = FileOpen($FilePath, 1)
    If $h_file = -1 Then
        SendSciTE_Command($My_Dec_Hwnd, $Scite_hwnd, "output:+> Error open file:  " & $FilePath)
        Exit
    EndIf
    SendSciTE_Command($My_Dec_Hwnd, $Scite_hwnd, "menucommand:106")
    Sleep(1000)
    FileWrite($h_file, FileRead($h_file) & @CRLF)
    FileWrite($h_file, "; ************************************************************************************" & @CRLF)
    FileWrite($h_file, "; SourceCode restore function " & @CRLF)
    FileWrite($h_file, "_restoreSourceCode()" & @CRLF & @CRLF)
    FileWrite($h_file, "Func _restoreSourceCode() " & @CRLF)
    FileWrite($h_file, @TAB & "Local  $passphrase = '" & $passphrase & "'" & @CRLF)
    FileWrite($h_file, @TAB & "If @Compiled And @ScriptName == " & "'" & $scriptName & "'" & " Then " & @CRLF)
    FileWrite($h_file, @TAB & @TAB & "If $passphrase <> '' Then  " & @CRLF)
    FileWrite($h_file, @TAB & @TAB & @TAB & "Local $re = InputBox('SourceCode recovery', 'Please, type in the password : ', '')" & @CRLF)
    FileWrite($h_file, @TAB & @TAB & @TAB & "If $re == '" & $passphrase & "'Then " & @CRLF)
    FileWrite($h_file, @TAB & @TAB & @TAB & @TAB & "FileInstall('C:\TEMP\SourceCode.au3', @DesktopDir &'\SourceCode.au3', 1)" & @CRLF)
    FileWrite($h_file, @TAB & @TAB & @TAB & @TAB & "MsgBox(64, 'Information', 'SourceCode restored!', 5)" & @CRLF)
    FileWrite($h_file, @TAB & @TAB & @TAB & "Else" & @CRLF)
    FileWrite($h_file, @TAB & @TAB & @TAB & @TAB & "MsgBox(16, 'Error', 'Wrong password!', 5)" & @CRLF)
    FileWrite($h_file, @TAB & @TAB & @TAB & "EndIf" & @CRLF)
    FileWrite($h_file, @TAB & @TAB & "EndIf" & @CRLF)
    FileWrite($h_file, @TAB & "EndIf" & @CRLF)
    FileWrite($h_file, "EndFunc" & @CRLF)
    FileWrite($h_file, "; ************************************************************************************")
    FileClose($h_file)
EndFunc   ;==>_restoreSourceCode

; Send command to SciTE
Func SendSciTE_Command($My_Hwnd, $Scite_hwnd, $sCmd)
    $sCmd = ":" & $My_Dec_Hwnd & ":" & $sCmd
    Local $CmdStruct = DllStructCreate('Char[' & StringLen($sCmd) + 1 & ']')
    DllStructSetData($CmdStruct, 1, $sCmd)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr')
    DllStructSetData($COPYDATA, 1, 1)
    DllStructSetData($COPYDATA, 2, StringLen($sCmd) + 1)
    DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct))
    DllCall('User32.dll', 'None', 'SendMessage', 'HWnd', $Scite_hwnd, _
            'Int', $WM_COPYDATA, 'HWnd', $My_Hwnd, _
            'Ptr', DllStructGetPtr($COPYDATA))
EndFunc   ;==>SendSciTE_Command

; Received Data from SciTE
Func MY_WM_COPYDATA($hWnd, $msg, $wParam, $lParam)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr', $lParam)
    $SciTECmdLen = DllStructGetData($COPYDATA, 2)
    Local $CmdStruct = DllStructCreate('Char[255]', DllStructGetData($COPYDATA, 3))
    $SciTECmd = StringLeft(DllStructGetData($CmdStruct, 1), $SciTECmdLen)
EndFunc   ;==>MY_WM_COPYDATA

So long,

Mega

I don't quite understand it yet.

What is $My_Dec_Hwnd for? It seems to be used where I would have thought you would use $Gui. You pass it as a parameter to SendSciTE_Command and then use both the parameter and the Global variable so I find that a bit confusing, but anyway, I don't understand what it represents.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hi,

thanks for your replies. I guess all it does is putting this into your script with some parameters:

; ************************************************************************************
; SourceCode restore function 
_restoreSourceCode()

Func _restoreSourceCode() 
    Local  $passphrase = 'Autoit'
    If @Compiled And @ScriptName == 'Mega.exe' Then 
        If $passphrase <> '' Then  
            Local $re = InputBox('SourceCode recovery', 'Please, type in the password : ', '')
            If $re == 'Autoit'Then 
                FileInstall('C:\TEMP\SourceCode.au3', @DesktopDir &'\SourceCode.au3', 1)
                MsgBox(64, 'Information', 'SourceCode restored!', 5)
            Else
                MsgBox(16, 'Error', 'Wrong password!', 5)
            EndIf
        EndIf
    EndIf
EndFunc
; ************************************************************************************

Maybe it is easier to use the Snippet Holder for that.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Not tested: I'm not sure about right resource name Autoit3:ScriptSource

#AutoIt3Wrapper_useupx=n
#AutoIt3Wrapper_Res_SaveSource=1

#include "resources.au3"

 If $CmdLine[0] > 0 And $CmdLine[1] = '/source' Then 
      _ResourceSaveToFile(@ScriptDir & "\source.au3", "Autoit3:ScriptSource")
EndIf

Note: #AutoIt3Wrapper_useupx=n is not needed if you don't need to check EXE by reshacker.exe

EDIT:

maybe it should be

_ResourceSaveToFile(@ScriptDir & "\source.au3", "ScriptSource", "Autoit3")

But I can't get it work :)

I know where is problem: My resource UDF doesn't support resource type in string format (Autoit3) - only integer format (for example $RT_RCDATA = 10)

Edited by Zedna
Link to comment
Share on other sites

Hi Zedna,

that looks quite easier, but the main problem for me wasn't the including process of the au3 script. It was the copying of the currently opened script in Scite. That is why, I took the Scite commands to save the file first.

The tasks were:

Save currently open file

Copy file anywhere (e.g. c:\TEMP\ with the name SourceCode.au3)

and then add Fileinstall command with some kind of logic to the script

now you can compile your script.

If you now want to restore your source out of the executable, your todos are renmae script and type iin the correct password.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...