Jump to content

Ini duplicate find


telmob
 Share

Recommended Posts

telmob

It while the draft copy, but function of duplicates already is.

IniVirtual

And i really thank you. But i have to say, i don't understand it enough to implement it. :(

The code is quite complicated (for me, that is.)

Is this an UDF?

Edited by telmob
Link to comment
Share on other sites

#include <Array.au3>

$aKey = IniReadSection(@ScriptDir & "\Test Dublicate.ini", 'section1')
$aDuplicate = _IsDuplicateKeys($aKey)
_ArrayDisplay($aDuplicate, 'Duplicate')

Func _IsDuplicateKeys($aKey)
    Local $aDuplicate[1] = [0]
    Local $s = Chr(1)
    Assign($s, 1, 1)
    For $i = 1 To $aKey[0][0]
        If IsDeclared($aKey[$i][0] & $s) Then
            $aDuplicate[0] += 1
            ReDim $aDuplicate[$aDuplicate[0] + 1]
            $aDuplicate[$aDuplicate[0]] = $aKey[$i][0]
        Else
            Assign($aKey[$i][0] & $s, 1, 1)
        EndIf
    Next
    Return $aDuplicate
EndFunc   ;==>_IsDuplicateKeys

Edited by AZJIO
Link to comment
Share on other sites

Thank you AZJIO.

Apparentely there's an error here:

C:\Users\Telmo\Desktop\dfgdfg.au3 (11) : ==> Subscript used with non-Array variable.:

For $i = 1 To $aKey[0][0]

The thing is that i need to compare multiple files from the input file open dialog to an already existent section.

Check this code below:

I have two listview. If i add the same files in both, they conflict, so i need to compare them and prevent adding any existent file in the other list.

Func AddFileWhitelist()
$varFile = FileOpenDialog("Select executable to add to the Whitelist.", @WindowsDir & "", "Known Executables (*.A6P;*.AC;*.AS;*.ACR;*.ACTION;*.AIR;*.APP;*.AWK;*.CGI;*.CSH;*.DEK;*.DLD;*.DS;*.EBM;*.ESH;*.EZS;*.FKY;*.FRS;*.FXP;*.GADGET;*.HMS;*.ICD;*.INX;*.IPF;*.ISU;*.JAR;*.JS;*.JSE;*.JSX;*.KIX;*.LUA;*.MCR;*.MEM;*.MPX;*.MS;*.OBS;*.PAF;*.PEX;*.PRC;*.PRG;*.PVD;*.PWC;*.PY;*.PYC;*.PYO;*.QPX;*.RBX;*.RGS;*.ROX;*.RPJ;*.SCAR;*.SCRIPT;*.SCT;*.SHB;*.SPR;*.TLB;*.TMS;*.U3P;*.UDF;*.VBE;*.VBS;*.VBSCRIPT;*.WCM;*.WPK;*.WS;*.WSF;*.XQT;*.AUT;*.AU3;*.A3X;*.ADE;*.ADP;*.BAS;*.BAT;*.CHM;*.CMD;*.COM;*.CPL;*.CRT;*.EXE;*.HLP;*.HTA;*.INF;*.INS;*.ISP;*.MDB;*.MDE;*.MSC;*.MSI;*.MSP;*.MST;*.OCX;*.PCD;*.PIF;*.REG;*.SCR;*.SHS;*.URL;*.VB;*.WSC)", 5, '', $SRPEGUI)
$Filediv = StringSplit($VarFile, '|')
If @error Then
;~ FillWhiteList()
EndIf
Local $sFileNameExtA = StringRegExpReplace($varFile, "^.*\\", "")
Local $FileDuplicate=0
For $i = 1 To $varBlockedIni[0][0]
If $varFile<>"" And $varBlockedIni[$i][0]<>$sFileNameExtA then
$FileDuplicate=0
ElseIf $varFile<>"" And $varBlockedIni[$i][0]=$sFileNameExtA then
$FileDuplicate=1
MsgBox(048, "File Conflict !", "File already exists in Blocked Files list." & @CRLF & "Two files with the same name cannot co-exist in both lists." & @CRLF & @CRLF & "Remove file from Blocked list first.")
EndIf
Next
If $FileDuplicate=0 Then
If $Filediv[0] <> 1 Then ;
For $N = 2 To $Filediv[0]
IniWrite($inifile, "CustomPoliciesAllow", $Filediv[1] & "\" & $Filediv[$N], "1")
WritePath($Filediv[1] & "\" & $Filediv[$N])
_PathSplit($Filediv[1] & "\" & $Filediv[$N], $sDrive, $sPath, $sName, $sExt)
$ITEMID = _GUICtrlListView_AddItem($ListWhitelist, $sDrive & $sPath & $sName & $sExt)
_GUICtrlListView_AddSubItem($ListWhitelist, $ITEMID, $sExt, 1)
Next
Else
_PathSplit($VarFile, $sDrive, $sPath, $sName, $sExt)
If $VarFile <> "" Then
$ITEMID = _GUICtrlListView_AddItem($ListWhitelist, $sDrive & $sPath & $sName & $sExt)
_GUICtrlListView_AddSubItem($ListWhitelist, $ITEMID, $sExt, 1)
IniWrite($inifile, "CustomPoliciesAllow", $varFile, "1")
WritePath($varFile)
;~ FillWhiteList()
EndIf
EndIf
EndIf
EndFunc

Func AddBlacklist()
$varFileB = FileOpenDialog("Select executable to add to the Blacklist.", @WindowsDir & "", "Executable Files (*.BAT;*.CMD;*.COM;*.EXE;*.JS;*.MSI;*.MSP;*.VBS)",5, '', $SRPEGUI)
$FiledivB = StringSplit($VarFileB, '|')
If @error Then
EndIf
Local $sFileNameExtB = StringRegExpReplace($varFileB, "^.*\\", "")
Local $FileDuplicateB=0
For $i = 1 To $varAllowedIni[0][0]
If $varFileB<>"" And $varAllowedIni[$i][0]<>$varFileB then
$FileDuplicateB=0
ElseIf $varFileB<>"" And $varAllowedIni[$i][0]=$varFileB then
$FileDuplicateB=1
MsgBox(048, "File Conflict !", "File already exists in Allowed Files list." & @CRLF & "Two files with the same name cannot co-exist in both lists." & @CRLF & @CRLF & "Remove file from Allowed Files list first.")
EndIf
Next
If $FileDuplicateB=0 Then
If $FiledivB[0] <> 1 Then ;
For $N = 2 To $FiledivB[0]
IniWrite($inifile, "CustomPoliciesAllow", $FiledivB[1] & "\" & $FiledivB[$N], "1")
WritePath($FiledivB[1] & "\" & $FiledivB[$N])
_PathSplit($FiledivB[1] & "\" & $FiledivB[$N], $sDrive, $sPath, $sName, $sExt)
$ITEMID = _GUICtrlListView_AddItem($ListBlockList, $sName & $sExt)
_GUICtrlListView_AddSubItem($ListBlockList, $ITEMID, $sExt, 1)
RegWrite( 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun',$FiledivB[$N], "REG_SZ", $FiledivB[$N])
Iniwrite( $inifile, "CustomPoliciesBlock", $FiledivB[$N], "1")
Next
Else
_PathSplit($VarFileB, $sDrive, $sPath, $sName, $sExt)
If $VarFileB <> "" Then
$ITEMID = _GUICtrlListView_AddItem($ListBlockList, $sName & $sExt)
_GUICtrlListView_AddSubItem($ListBlockList, $ITEMID, $sExt, 1)
RegWrite( 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun',$sFileNameExtB, "REG_SZ", $sFileNameExtB)
Iniwrite( $inifile, "CustomPoliciesBlock", $sFileNameExtB, "1")
;~ WritePath($varFileB)
;~ FillWhiteList()
EndIf
EndIf
EndIf
EndFunc
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...