Jump to content

Arrays and I


 Share

Recommended Posts

Could I make an array in a ini file and call on it to do an InetGet?

Example:

I have 5 files that I want downloaded but the file names change. I want to be able to rather than rewrite the scrip when they change just update an ini file with the changes.

Link to comment
Share on other sites

Don't see why you couldn't. an ini is just like a saved array

inireadsection will put the contents of a section into an array

or you could use numbers for your ini keys 1, 2, 3 etc and use an incrementing variable in an iniread

$i=1
do
$link=iniread(file path,section,$i,"")
;do whatever
$i+=1
until $i>3

just a couple variations on how to use it.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

JonCross,

As for ini and array, Look at IniReadSection() and IniWriteSection()

You could use IniReadSection() to load into an array, and then loop the array with InetGet().

Realm

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

Ok, I thought it was supposed to work. Maybe what I have done is not proper. Would anyone mind looking over a section of my script.

$Files is specified in an ini file as to www.domainname.com\directory

$include is specified in an ini file as to what files in $files to download

Global $settings = (@ScriptDir & "\settings.ini")
Global Const $s_datfile = IniRead($settings, 'settings', 'datafile', '')
Global Const $s_DatFile_Local = @TempDir & '\crossautomation_update.dat'
Global $s_Server, $s_updatedir, $Server
Global $iIdleTime
Global Const $Ver = "5.2.1"

Func WebStart()
    InetGet($s_datfile, $s_DatFile_Local, 1)
    If @error <> 0 Then
        MsgBox(0, "ERROR", "Error with Server")
        Sleep(4000)
        Exit
    EndIf
    $s_Server = IniRead($s_DatFile_Local, 'config', 'server', '')
    $s_updatedir = IniRead($s_DatFile_Local, 'config', 'update', '')
    $s_local = IniRead($s_DatFile_Local, 'config', 'local', '')
    $s_title = IniRead($s_DatFile_Local, 'config', 'title', '')
    $s_files = IniRead($s_DatFile_Local, 'config', 'files', '')
    $s_include = IniReadSection($s_DatFile_Local, "include")
    Global $Server = $s_Server
    Global $Update = $s_updatedir
    Global $Local = $s_local
    Global $Title = $s_title
    Global $files = $s_files
    Global $Include = $s_include
    FileDelete($s_DatFile_Local)
    FileCreateShortcut($Local & "\ControlDaemon.exe", @StartupDir & "\ControlDaemon.lnk", $Local)
    $testvar = InetGet($files & $Include, @ScriptDir, 1)
    Exit
    ;Self Update Function at Startup
    _UpdateCheck()
EndFunc   ;==>WebStart
Edited by JonCross
Link to comment
Share on other sites

Hello JonCross,

IniReadSection() reads into a 2D Array, and InetGet() uses absolute addresses, or strings containing absolute address.

Trying to pass an array to the function InetGet() will not work as you have intended. You need to build a loop that will allow InetGet() to work with each absolute address in InetGet(). Without seeing the contents of your ini file, or knowing exactly what results your expecting, it's difficult to help you. However, I think I understand the basics of what you want. Please Correct me If I am wrong with a full description of what results your expecting, what problems you are currently haveing with your code.

Also I noticed you have called to 'Exit' the script before the rest of the code finishes. This will Exit your script before it has an oportunity to run your custom function labaled '_UpdatedCheck()', So I would advise removing the Exit. I will leave that in place for now, incase you are using it for testing purposes.

Also I noticed you have assigned @ScriptDir for a place to download the file to, However, you need a name for the file as well, I will fix a temporary name using the current Link # being used with '.txt' for the extension for the example. However you should change that to your needs, especialy the file extension.

Make sure that The link in your @TempDir & '\crossautomation_update.dat' file under section 'config', key 'files' ends with a '\' or atleast the beginning of each link in section 'include' begins with one.

Assuming that all the data in your file @TempDir & '\crossautomation_update.dat' under section 'include' is only links you wish to download to the script directory folder. I will also assume the ini key is irrelevent to the download, and the value following the equal sign is the link you wish to download. If this is correct, then this modification of your script should help you. Make sure you links are absolutely correct. I have done similar downloads before, and found that in some cases when the link I am calling is not present, it will download some of the source code fromt he index page of the website url in place of the actual file you wish to get.

Global $settings = (@ScriptDir & "\settings.ini")
Global Const $s_datfile = IniRead($settings, 'settings', 'datafile', '')
Global Const $s_DatFile_Local = @TempDir & '\crossautomation_update.dat'
Global $s_Server, $s_updatedir, $Server
Global $iIdleTime
Global Const $Ver = "5.2.1"

Func WebStart()
    InetGet($s_datfile, $s_DatFile_Local, 1)
    If @error <> 0 Then
        MsgBox(0, "ERROR", "Error with Server")
        Sleep(4000)
        Exit
    EndIf
    $s_Server = IniRead($s_DatFile_Local, 'config', 'server', '')
    $s_updatedir = IniRead($s_DatFile_Local, 'config', 'update', '')
    $s_local = IniRead($s_DatFile_Local, 'config', 'local', '')
    $s_title = IniRead($s_DatFile_Local, 'config', 'title', '')
    $s_files = IniRead($s_DatFile_Local, 'config', 'files', '') ;The Value of this should end with a '\' or
                                                                ;each $s_include link should begin with one
    $s_include = IniReadSection($s_DatFile_Local, "include") ;This reads in to a 2D Array.
    Global $Server = $s_Server
    Global $Update = $s_updatedir
    Global $Local = $s_local
    Global $Title = $s_title
    Global $files = $s_files
    Global $Include = $s_include
    FileDelete($s_DatFile_Local)
    FileCreateShortcut($Local & "\ControlDaemon.exe", @StartupDir & "\ControlDaemon.lnk", $Local)
    For $link = 1 To UBound($Include)-1
        InetGet($files & $Include[$link][1], @ScriptDir & '\TempName' & $link & '.txt', 1)
    Next
    Exit
    ;Self Update Function at Startup
    _UpdateCheck()
EndFunc   ;==>WebStart

Hope this helps.

Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

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...