Jump to content
Sign in to follow this  
Decipher

Decode Bencode Function - Help Please!

Recommended Posts

Decipher

I've been working on a huge project. Its a torrent downloader. I can't show the source or anything, sorry guies, that would be frowned upon by the Autoit forum moderators. I won't post a link either but it will be posted on google code in the near future so you can always search for it. I believe that any euthastic torrent downloader will absolutely love it. I would like to have a function to decode bencode torrent files. I've done the research. I need help writing this function. I thank you all in advance and really appreciate any help I recieve from these forums.

Features to implement once I can decode bencoded files:

(1) Generate magnet links from torrent files.

(2) List files inside torrent files.

(3) Conviently parse tracker response data for checking torrent trackers for torrent information before adding them to the generated magnet link and passing it to the client which actually downloads the torrent.

Spec - Wiki Theory Bittorrent Spec - Bencode - At the bottom of this page there are links to implementations in other languages.

Info - Wikipedia - Bencode

Bencode Editor - https://sites.google.com/site/ultimasites/bencode-editor - This is allegedly written in Autoit. Though I cannot find the source.

I completely rewrote the functions as one function. Its works well but is not exactly what I need. now that I can extract the information I need to associate each type appropiately.

For Example:

Strings => Integers

Lists => Strings

Dictionaries => Strings

Seeds => 1

Peers => 5

Tracker List => Tracker|Tracker|Tracker

This is complicated because lists can be in lists in dictionaries inside of dictionaries or other lists.

#include <array.au3>

$Timer = TimerInit()
Example(@ScriptDir & 'ubuntu-12.04-desktop-i386.iso.torrent')
ConsoleWrite(@CRLF & @CRLF & "Time: " & Round(TimerDiff($Timer)/1000, 1) & " second(s)" & @CRLF)

Func Example($sFilePath)
   Local $Bencode = FileRead($sFilePath)
   Local $aData = _Decode_Bencode($Bencode)
   _ArrayDisplay($aData)
EndFunc

Func _Decode_Bencode($sBencoded_Data)
   Local $iIndex = 0, $sDecoded_Data, $iEndIndex, $iDecoded_Integer, $iDecoded_Dim_0 = 0, $iDecoded_Dim_1 = 0, $iDecoded_Indent = 0
   Local $aDecoded_Array[20][20]
   If Not IsString($sBencoded_Data) Then
      Return SetError(1, 0, 0)
   EndIf
   Local $aBencoded_Data = StringSplit($sBencoded_Data, '', 2)
   While $iIndex <> UBound($aBencoded_Data, 1) - 1
      Switch $aBencoded_Data[$iIndex]
         Case "e"
            $iIndex += 1
            $iDecoded_Dim_0 += 1
            If $iDecoded_Indent <> 0 Then $iDecoded_Indent -= 1
            $iDecoded_Dim_1 = $iDecoded_Indent
            ContinueLoop
         Case "l"
            $iIndex += 1
            $iDecoded_Dim_1 = $iDecoded_Indent
            $iDecoded_Dim_0 += 1
            $iDecoded_Indent += 1
            ContinueLoop
         Case "d"
            $iIndex += 1
            $iDecoded_Dim_1 = $iDecoded_Indent
            $iDecoded_Dim_0 += 1
            $iDecoded_Indent += 1
            ContinueLoop
         Case "i"
            $iEndIndex = _ArraySearch($aBencoded_Data, "e", $iIndex, 0, 1)
            $sDecoded_Data = ""
            For $i = $iIndex + 1 To $iEndIndex - 1 Step 1
               $sDecoded_Data &= $aBencoded_Data[$i]
               $aBencoded_Data[$i] = ""
            Next
            $aDecoded_Array[$iDecoded_Dim_0][$iDecoded_Dim_1] = $sDecoded_Data
            $iIndex = $iEndIndex - 1
            $iDecoded_Dim_1 += 1
         Case 0 To 9
            $iDecoded_Integer = ""
            $iEndIndex = _ArraySearch($aBencoded_Data, ":", $iIndex)
            For $i = $iIndex To $iEndIndex - 1 Step 1
               $iDecoded_Integer &= $aBencoded_Data[$i]
               $aBencoded_Data[$i] = ""
            Next
            $sDecoded_Data = ""
            For $i = $iEndIndex + 1 To $iEndIndex + $iDecoded_Integer Step 1
               $sDecoded_Data &= $aBencoded_Data[$i]
               $aBencoded_Data[$i] = ""
            Next
            $aDecoded_Array[$iDecoded_Dim_0][$iDecoded_Dim_1] = $sDecoded_Data
            $iIndex = $iEndIndex + $iDecoded_Integer
            $iDecoded_Dim_1 += 1
      EndSwitch
      $iIndex += 1
   WEnd
   Return $aDecoded_Array
EndFunc

*Edited:

Original vbscript - http://demon.tw/my-work/vbs-bencode.html

Bencoded Torrent File: ubuntu-12.04-desktop-i386.iso.torrent

Thanks in advance!

Edited by Decipher

Spoiler

censored.jpg

 

Share this post


Link to post
Share on other sites
Mat

Unless you are actively encouraging piracy and illegal activity, I see no reason why this should be frowned upon.

Torrents are a fantastic way to distribute large files. Freeware projects that create large databases, or OS' like linux wouldn't be able to pay for hosting to support large http downloads, so wouldn't exist without p2p distribution.

Share this post


Link to post
Share on other sites
Decipher

Unless you are actively encouraging piracy and illegal activity, I see no reason why this should be frowned upon.

Torrents are a fantastic way to distribute large files. Freeware projects that create large databases, or OS' like linux wouldn't be able to pay for hosting to support large http downloads, so wouldn't exist without p2p distribution.

I had posted the code before where it search the piratebay exclusively, Topic labeled TPB Torrent Downloader was deleted. If a mod happens to see this post please advice if I can post the code or not.

Edited by Decipher

Spoiler

censored.jpg

 

Share this post


Link to post
Share on other sites
ProgAndy

You casees with "or", "and" are most certainly wrong.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
Decipher

They were all originally "And" but I replaced most of them with "Or". Which would be correct? I thought it might be better to use a < or > operators depending on whats happening in that function but I'm unsure.

Ex. Case $a >= 0 And <= 9

Edited by Decipher

Spoiler

censored.jpg

 

Share this post


Link to post
Share on other sites
ProgAndy

You cannot ask for a range with And. You have to specify the variable for each expression: Case $a >= 0 And $a <= 9


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
BrewManNH

Your case statement needs to be rewritten like the code below.

Case $c = "0" Or $c = "$1" Or $c = "2" Or $c = "3" Or $c = "4" Or $c = "5" Or $c = "6" Or $c = "7" Or $c = "8" Or $c = "9"

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Decipher

Thanks, I'll update the script above. @BrewManNH I assume the reason for coding it that way would be because of the variable type correct?

Edited by Decipher

Spoiler

censored.jpg

 

Share this post


Link to post
Share on other sites
Blue_Drache

There is no typecasting in AutoIt. An integer is a string is a double is a long.

  • Like 1

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites
BrewManNH

Thanks, I'll update the script above. @BrewManNH I assume the reason for coding it that way be because of the variable type correct?

You might be better off with a Switch statement in that section then you could just do it this way.

Switch $c
     Case "l"
     Case "d"
     Case "i"
     Case 0 To 9
EndSwitch

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Decipher

As the _Decode_String and Integer functions are working properly the key to fix this is:

Lists

Lists are encoded as follows: l<bencoded values="">e

The initial l and trailing e are beginning and ending delimiters. Lists may contain any bencoded type, including integers, strings, dictionaries, and even lists within other lists. Example: l4:spam4:eggse represents the list of two strings: [ "spam", "eggs" ]

Dictionaries

Dictionaries are encoded as follows: d<bencoded string=""><bencoded element="">e

The initial d and trailing e are the beginning and ending delimiters. Note that the keys must be bencoded strings. The values may be any bencoded type, including integers, strings, lists, and other dictionaries. Keys must be strings and appear in sorted order (sorted as raw strings, not alphanumerics). The strings should be compared using a binary comparison, not a culture-specific "natural" comparison. Example: d3:cow3:moo4:spam4:eggse represents the dictionary { "cow" => "moo", "spam" => "eggs" } Example: d4:spaml1:a1:bee' represents the dictionary { "spam" => [ "a", "b" ] } Example: d9:publisher3:bob17:publisher-webpage15:www.example.com18:publisher.location4:homee represents { "publisher" => "bob", "publisher-webpage" => "www.example.com", "publisher.location" => "home" }

I can not figure out how to fix these two iterative functions.

Edited by Decipher

Spoiler

censored.jpg

 

Share this post


Link to post
Share on other sites
Maffe811

Im just thinking, if every "dictionary" is like that why not just make something that finds a number, removes the colon and reads the string until the next number and repeats.

d3:cow3:moo4:spam4:eggse

remove d

-

skip to next number

skip past number and :

read until next number

Save that string somewhere

-

repeat above until no more numbers

remove e at the end


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites
Decipher

Im just thinking, if every "dictionary" is like that why not just make something that finds a number, removes the colon and reads the string until the next number and repeats.

d3:cow3:moo4:spam4:eggse

remove d

-

skip to next number

skip past number and :

read until next number

Save that string somewhere

-

repeat above until no more numbers

remove e at the end

I understand your logic. I would like the Bdecode function to be able to decode any Bencode according to the spec.

d58:http://thisisaurlwithanamountofcharactersandthenumber8plus3:moo4:spam4:eggse

This would break the function. I thought to use RegEx but I don't know how to write it.

The way the _Decode_String() function is wriiten:

The String function would only be called if the starting character is a number 0 To 9.

Find the first colon after the starting character.

Extract the integer between the said number and the colon. The integer represents the amount of characters in a string.

Use StringMid to extract the string from the colon to the number of characters specified by the extracted integer.

For example: d5:fifthe

The Decode_Dict(String) function would call _Decode_String(String, StartingCharacter)

If 'd' is the place value of the starting character then the integer to be extracted is between 1 and 3(Colon)

5 is the amount of character in the string or content after the colon.

so we can then use stringmid to extract exactly that string.

We then return an array whose's first index is the decoded string 'fifth' and the second should be the position of 'e' an integer.

The Decode_Dict() function would then return because the starting character is an 'e'

That's the best I can explain it. Thanks for your suggestion but I'd really like to just fix the functions I have now then I could go back and optimize the code make changes, etc.

Edited by Decipher

Spoiler

censored.jpg

 

Share this post


Link to post
Share on other sites
Maffe811

So the number represent the ammount of letters that are gonna follow ?

(Sorry if you said already, but its hard to pay attention to everything)

I would put the string in a variable, and remove pices of the variable and saving the pices while you remove them.

This would make for easy coding i would belive.

Remind me to give it a go if i have time tomorrow!


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites
Decipher

I know that this shouldn't be as complicated as is to me but I've made progress I can actually can get some output. ;)

Please do and please run the code, I just updated it and the problems with it are very apparent than before. Thanks for any help.

Edited by Decipher

Spoiler

censored.jpg

 

Share this post


Link to post
Share on other sites
Decipher

How can I make an array effectively without creating an array inside an array.

$aArray[1][0] = "List"

$aArray[1][1] = "Delimited-Strings"

$aArray[2][0] = "Spam"

$aArray[2][1] = "Eggs"

$aArray[3][0] = "Dictionary"

$aArray[3][1] = "Delimited-Keys"


Spoiler

censored.jpg

 

Share this post


Link to post
Share on other sites
Robjong

#include <Array.au3>

Local $aArray[4][2] = [[0, 1], [2, 3], ['4', '5']]
$aArray[3][0] = 6
$aArray[3][1] = '7'

_ArrayDisplay($aArray)

?

Share this post


Link to post
Share on other sites
Decipher

I would like to create an array similiar to this:

Posted Image

$aArray[0][0] = announce

$aArray[0][1] = http://torrent.ubuntu.com:6969/announce

$aArray[1][0] = announce-list

$aArray[1][1] = http://torrent.ubuntu.com:6969/announce<--delimiter-->http://ipv6.torrent.ubuntu.com:6969/announce

$aArray[2][0] = comment

$aArray[2][1] = Ubuntu CD releases.ubuntu.com

$aArray[3][0] = creation date

$aArray[3][1] = 1335433885

$aArray[4][0] = length

$aArray[4][1] = 735358976

and so on.

Dictionary => Key Name would be [n][0] and value [n][1]

List => StringName would be [n][0] and value [n][1] if value is a list then delimit the strings and/or integers

This way I will always have a two dimensional array.

If I wanted the announce list I could just _ArraySearch for announce-list and StringSplit the value.

I can not determine how to manipulate the code to work as described.

Edited by Decipher

Spoiler

censored.jpg

 

Share this post


Link to post
Share on other sites
Maffe811

I can't see what the problem is.

Im sorry if i understand, but my ability to understand what you have written just isn't there.

You want multiple arrays without having an array in an array?

Why not give the array different names... ?

Sorry, but im lost.


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites
Decipher

I only want one two dimensional array containing the decoded data as described above the problem is how to do that when there are sometimes lists in lists in dictionaries in dictionaries or vice versa when decoding the bencode.

Edited by Decipher

Spoiler

censored.jpg

 

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I was trying to insert function header to the functions of my script, but, in the SciTE console, this appears:
      Function or struct definition not found, unable to insert header. @Jos Any suggestion?
      Thanks in advance.

      Best Regards.
    • Ascer
      By Ascer
      Hello.
      A couple week ago i've started learning API Interface for different websites. In this fact sometimes you have to encode your "photo" or "document.body" to send request.
      Functions to encode and decode Base64 was already created by others. Unfortunately i have troubles with running it on Windows R 2008, also speed was terrible.
      I try to find alternative way to code data. 
      I've read about Microsoft "XMLDOM" and created a one simple function to Encode / Decode data to base64binary, base64url
      Thanks for Ghads on Wordpress i coverted a part of his lines from VBscript to AutoIT
      ;============================================================================================================================== ; Function: base64($vCode [, $bEncode = True [, $bUrl = False]]) ; ; Description: Decode or Encode $vData using Microsoft.XMLDOM to Base64Binary or Base64Url. ; IMPORTANT! Encoded base64url is without @LF after 72 lines. Some websites may require this. ; ; Parameter(s): $vData - string or integer | Data to encode or decode. ; $bEncode - boolean | True - encode, False - decode. ; $bUrl - boolean | True - output is will decoded or encoded using base64url shema. ; ; Return Value(s): On Success - Returns output data ; On Failure - Returns 1 - Failed to create object. ; ; Author (s): (Ghads on Wordpress.com), Ascer ;=============================================================================================================================== Func base64($vCode, $bEncode = True, $bUrl = False) Local $oDM = ObjCreate("Microsoft.XMLDOM") If Not IsObj($oDM) Then Return SetError(1, 0, 1) Local $oEL = $oDM.createElement("Tmp") $oEL.DataType = "bin.base64" If $bEncode then $oEL.NodeTypedValue = Binary($vCode) If Not $bUrl Then Return $oEL.Text Return StringReplace(StringReplace(StringReplace($oEL.Text, "+", "-"),"/", "_"), @LF, "") Else If $bUrl Then $vCode = StringReplace(StringReplace($vCode, "-", "+"), "_", "/") $oEL.Text = $vCode Return $oEL.NodeTypedValue EndIf EndFunc ;==>base64  
       
    • Amixg
      By Amixg
      Hi! I have another problem with AutoIT.  You see, I'm still the one who's just starting out with this great programming language. I have a problem with AutoIT, it seems not to recognize the "StringReplace" function even when it is by default. The code was made half in KODA and half of my own. It is a software programmed for the Italian language (I am Italian) and translate the SMS language into Italian correct. Would you help me? Thanks in advance.
       
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $hull = "hello" StringReplace($hull, "hello", "hellx") $Form1 = GUICreate("Linguaggio SMS A Italiano", 507, 498, 192, 124) $Edit1 = GUICtrlCreateEdit("", 24, 40, 465, 177) GUICtrlSetData(-1, "") $Label1 = GUICtrlCreateLabel("Inserisci qui il testo che non riesci a capire:", 24, 8, 205, 17) $Label2 = GUICtrlCreateLabel("Ecco il testo tradotto(non toccare questo campo):", 27, 237, 237, 17) $Edit2 = GUICtrlCreateEdit("", 24, 264, 465, 137) GUICtrlSetData(-1, "") $Button1 = GUICtrlCreateButton("Traduci", 104, 424, 249, 49) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 StringReplace(GUICtrlGetData($Label1), "qlc", "qualcuno") StringReplace(GUICtrlGetData($Label1), "qls", "qualcosa") StringReplace(GUICtrlGetData($Label1), "ke", "che") StringReplace(GUICtrlGetData($Label1), "x", "per") StringReplace(GUICtrlGetData($Label1), "pls", "per favore") StringReplace(GUICtrlGetData($Label1), "tu6", "tu sei") StringReplace(GUICtrlGetData($Label1), "zzz", "mi fai dormire") StringReplace(GUICtrlGetData($Label1), "hagn", "Buonanotte") StringReplace(GUICtrlGetData($Label1), "tvtb", "Ti voglio tanto bene") StringReplace(GUICtrlGetData($Label1), "tat", "Ti amo tanto") StringReplace(GUICtrlGetData($Label1), "lafs", "Amore a prima vista") StringReplace(GUICtrlGetData($Label1), "fli?", "Flirtiamo?") StringReplace(GUICtrlGetData($Label1), "msidt", "Mi sono innamorato di te") StringReplace(GUICtrlGetData($Label1), "ba", "Bacio") StringReplace(GUICtrlGetData($Label1), "midi", "Mi dispiace.") StringReplace(GUICtrlGetData($Label1), "ntm", "Non ti merito") StringReplace(GUICtrlGetData($Label1), "tdp", "Togliti dai piedi.") StringReplace(GUICtrlGetData($Label1), "amò", "Amore") StringReplace(GUICtrlGetData($Label1), "ap", "A presto!") StringReplace(GUICtrlGetData($Label1), "cmq", "comunque") StringReplace(GUICtrlGetData($Label1), "cvd", "Ci vediamo dopo") StringReplace(GUICtrlGetData($Label1), "Tvb", "Ti voglio bene") StringReplace(GUICtrlGetData($Label1), "nn", "non") StringReplace(GUICtrlGetData($Label1), "risp", "rispondimi") StringReplace(GUICtrlGetData($Label1), "cel", "cellulare") StringReplace(GUICtrlGetData($Label1), "dom", "qualcosa") StringReplace(GUICtrlGetData($Label1), "nm", "numero") StringReplace(GUICtrlGetData($Label1), "fv", "favore") StringReplace(GUICtrlGetData($Label1), "-male", "meno male") StringReplace(GUICtrlGetData($Label1), "disc", "discoteca") StringReplace(GUICtrlGetData($Label1), "se#", "settimana") StringReplace(GUICtrlGetData($Label1), "+ o -", "più o meno") StringReplace(GUICtrlGetData($Label1), "ts", "torno subito") StringReplace(GUICtrlGetData($Label1), "tvtbcoa", "Ti voglio tanto bene come amica") EndSwitch WEnd  
    • Karnalsyn
      By Karnalsyn
      As with a lot of programming, the less manual repetition done to achieve the same outcome...the better.
      I package programs for network deployment at the organization I work for. Sometimes these applications require verbose messaging to the user, and sometimes by special request we have to turn that off and deploy silently.
      The way I currently handle these 2 scenarios is this.
      I have a function that builds the splashwin display screen to variable size depending on message length, and displays the desired message to the end user.
      Then at each point throughout my script as I need to make the user aware of what is currently happening, I inject a splashwin function call with the unique message pertaining to that specific event. ie. "Installing Microsoft Office, please wait..."
      In effort to build a more universal script to handle any type of request submitted. I've incorporated a switch command of '/silent'
      If cmdlineraw detects the usage of that switch when the script is triggered it sets a variable flag, ie. $silent = "on"
      Then at every splashwin call I make, I'm prefixing it with an IF statement that checks for the flag, and then does NOT display the message if that flag is "on". Or does display it if its not. Has worked for me just fine. But while I grow my programming skills and look for more streamlined ways of handling areas I find myself creating repetition. I'm curious if I can relocate that flag check. Taking it out of every single splashwin call, and injecting it into the function itself.
      Example of how I currently display or hide the splashwin based on command line...
      If StringInStr($cmdlineraw, "/silent", 0) Then
          $SilentSwitch = "ON"
      EndIf
      If $SilentSwitch = "OFF" Then SplashWin($Uninstalling & $ProductInfo[1][0])
      Some scripts have dozens of those splashwin calls littered throughout, so Is this the best approach I can take already? Or as stated earlier, can I pull the IF statement away from the splashwin call. And left the function as a whole either activate or deactivate as a result of the command line check.
    • wakillon
      By wakillon
      SciTE Hopper : Jump to Any line by one click and many other helpfull functions !


      As Ashalshaikh suggested me after leaving me the task to continue >SciTE Hopper, i open a new Topic about it.
      It will be more easy for futures updates.

      Many helpfull functions in contextual menu.
      SciTE Hopper is now multipurpose.
      • Color Catcher added
      • BinaryToAu3Kompressor added
      • TinyAu3Search replaced by StringFinder
      • RegJumper added
      • Edit With SciTE added (available in Options)
      • SpecialCharactersViewer added (available in Tray menu)
      New Contextual Menu :

      For a right Click on a function :

      • Copy function name
      • Insert a function header
      • Cut function
      • Copy function
      • Delete function
      • Create a variables List
      • Remove usseless Blank lines
      • Remove Debug lines ( all lines starting with ConsoleWrite or _ArrayDisplay )
      • Set AutoIt Code Layout
      • Remove Comments

      For entire script :

      • Create a functions List
      • Create a variables List
      • Remove usseless Blank lines
      • Remove Debug lines ( all lines starting with ConsoleWrite or _ArrayDisplay )
      • Set AutoIt Code Layout
      • Remove Comments
      • ( Open in SciTE a ) Duplicate of current Script in Temp Dir
      • ( Open in SciTE a ) Duplicate of current Script in Same Dir
      • Explore Parent Script Folder
      • Copy Script name
      • Copy Script path
      • Find Unused Functions
      • Find Unused Variables
      • Set all functions in alphabetic order.( func headers and regions ( in fact, all lines between functions ) are not supported.)

      SciTE Editor New Contextual Menu if SciTE Hopper is added ( in Options ) to SciTE Editor :
      when you made a selection in SciTE Editor you can :

      • Open a Reg Key in Regedit using RegJumper
      • Open a Url in your default Browser
      • Search on google in your default Browser
      • Search on AutoIt Website in your default Browser
      Now Can be added to windows start (minimized)
      Options are available by Tray Menu.
      A double click on tray icon will open clipboard content to SciTE Editor ( Handy when you have copied some code from your browser )

      How to proceed for add SciTE Hopper to SciTE Editor :
      Run Scite Editor, run Scite Hopper ( compiled! ) go to Options and select Add/Remove to SciTE Tab. then click on Add button and it's done !
      Right click on SciTE Editor and choose SciTE Hopper in Contextual Menu for run it when you need it !
      Update of 07 Dec 2017
      TinyAu3Search is replaced by StringFinder

      Previous downloads : 1287
      Script and compiled version are available in the download section
       
      Thanks to Ashalshaikh, Melba23, Th3 MMA, Alzri2, taitel, Manadar, taz742, Yashield, Authenticity, Xenobiologist for their help
      and asdf8 for his >Includes Helper and azjio for his >FileSearch.

      Hope it help you and happy Scripting !

       
×