Jump to content
Sign in to follow this  

Two listviews using same file?

Recommended Posts

Ive been playing with some code from aberration for a software installer

and i cant find a way to make this work

The files exist in a folder

The inifile has all the details for each file like this


Switch= /sp- /silent /norestart /NOCANCEL

Desc=Malwarebytes Anti Malware



And the Populate adds them all into the listviews on the tabs, which works fine but.

Func _Populate()
; Find all files in the Software folder and populate the tabs with the installers.
$f = FileFindFirstFile("Software/*.*")
Dim $array[1]
$i = 0
$s = FileFindNextFile($f)
If Not @error Then
$array[$i] = $s
$i += 1
ReDim $array[$i + 1]
Until @error
ReDim $array[$i]

For $i = 1 To UBound($array) Step 1
$category = IniRead($iniFile, $array[$i - 1], "Category", "5")
$desc = IniRead($iniFile, $array[$i - 1], "Desc", "")
If $category = 1 Then
GUICtrlCreateListViewItem($array[$i - 1] & "|" & $desc, $ListView1)
ElseIf $category = 2 Then
GUICtrlCreateListViewItem($array[$i - 1] & "|" & $desc, $ListView2)
ElseIf $category = 3 Then
GUICtrlCreateListViewItem($array[$i - 1] & "|" & $desc, $ListView3)
ElseIf $category = 4 Then
GUICtrlCreateListViewItem($array[$i - 1] & "|" & $desc, $ListView4)
ElseIf $category = 6 Then
GUICtrlCreateListViewItem($array[$i - 1] & "|" & $desc, $ListView6)
GUICtrlCreateListViewItem($array[$i - 1] & "|" & $desc, $ListView5)
EndFunc ;==>_Populate

For work we have a install after format pack of software and a lesser pack for other jobs but the packs contain some of the same files.

So i can get round this by renaming malware for eg to a different name and duplicating the file so i have the same file twice with 2 diff names, this works no probs but it means doubling up on size

Is there a way to get it to add malware to category1 and 2 on the same file?

Share this post

Link to post
Share on other sites

I'm not clear on the details of what you need but here are my initial thoughts. You could do several things. Firstly have you considered creating a shared file folder and removing duplicates. Secondly if the files need to be kept in separate folders then you could have a listview with several columns, each containing a separate path. The renaming option, you already tried that. I don't undertand why you need more than one listview.

Edited by czardas

Share this post

Link to post
Share on other sites

All the files are in one folder hence why i renamed

I just need the same file as per the example to show in both listviews so if they install listview 1 or 2 they get the same file installed with the additional files

I even tried adding a Category2=2 option to the ini and using an OR $category2 = 2 option but that didn't work either

All i need it to do is use the same file for 2 different listviews

The original is here

Edited by Chimaera

Share this post

Link to post
Share on other sites

At the moment you test for each file once and add it to the appropriate list view. I would be inclined to use binary for the categories (ini values) so you can use BitAnd to test if a file should be included in a listview. Your listviews would have the values 1, 2, 4, 8, 16 etc... A file belonging to listviews 1 and 2 would have a category value of BitOr(1, 2) = 3.

Edited by czardas

Share this post

Link to post
Share on other sites

So you mean make the categories in the ini into 1,2,4,8 etc rather than 1,2,3,4 etc

Ok i sort of get that bit but how would you mix the value 2's and 3's together in the same listview

And you mentioned BitAnd & BitOr was that a typo or do i need to use both?

If $category = BitAnd(1) Then ;== where do i get the second number from?
GUICtrlCreateListViewItem($array[$i - 1] & "|" & $desc, $ListView1)

If $category = BitAnd(3) Then
GUICtrlCreateListViewItem(BitOr($array[$i - 1],$array[$i - 1]) & "|" & $desc, $ListView1)

Umm im a bit lost here

Edited by Chimaera

Share this post

Link to post
Share on other sites

Here's a reproducer to show the concept of using binary flags for multiple attributes. It's just to give you an idea how this works. I have to work now, so no time to clean it up (not that I think it needs it: because it's just an example).

#include <Array.au3> ; For display purposes

; Reproducer starts here
; First read values from your ini file (or a database etc.)
; Reproducer for files and their binary flags (categories)
Dim $File_1a, $File_2, $File_3C, $File_45 ; File paths + extensions
$File_1a = "path_1a.exe"
$File_2 = "path_2.exe"
$File_3C = "path_3C.ini"
$File_45 = "path_45.txt"

Dim $iCategory_1a, $iCategory_2, $iCategory_3C, $iCategory_45 ; Ini values
$iCategory_1a = 1 ; = 1
$iCategory_2 = 6 ; = 4 + 2
$iCategory_3C = 5 ; = 4 + 1
$iCategory_45 = 15 ;= 8 + 4 + 2 + 1

; Main script Starts here
; Get files => Use FileListToArray for this in your actual script.
Dim $aFilesArray[5] = [4, $File_1a, $File_2, $File_3C, $File_45]

; Read the ini file to get these values.
Dim $aIniValue[5] = [4, $iCategory_1a, $iCategory_2, $iCategory_3C, $iCategory_45]

; In the following array, each column represents a different ListView.
Dim $aListViews[5][4]

; These headers are just for this reproducer only
$aListViews[0][0] = "LV1 = 1"
$aListViews[0][1] = "LV2 = 2"
$aListViews[0][2] = "LV3 = 4"
$aListViews[0][3] = "LV4 = 8"

;Now polpulate the columns (each representing a separate ListView).

For $iF = 1 To 4 ; For each file
    For $iLV = 0 To 3 ; For each column.
        If BitAND($aIniValue[$iF], 2^$iLV) = 2^$iLV Then $aListViews[$iF][$iLV] = $aFilesArray[$iF]


Edit - due to earlier distraction

Corrected a mistake on one of the ini values - which incidentally may range between 1 and 15 in the small scale example above - and altered two variable names. Any part of the code you don't understand, just ask.

Edited by czardas

Share this post

Link to post
Share on other sites

Sure. Implementing this will require you to do some modification to your code. It might help to visualise the binary. Each 1 represents one of the listviews in your example. 1000 - 0100 - 0010 - 0001

We can combine with BitOr

1001 - Listviews 1 and 4 (9)

1110 - Listviews 1, 2 and 3 (14)

We Can test if a 1 is present in any position using BitAnd

If BitAnd(7, 4) = 4 Then MsgBox(0, "", "True")

The code evaluates to True because there is a 1 in the third position in both 0111 and 0100.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...