Jump to content
Sign in to follow this  
ahmed9100

This is weird !!! i need help

Recommended Posts

ahmed9100

Hello every body whats wrong with my code !!

when i write any thing with my hand and press add it create the "ini" file in data folder :)

but

when i choose the file and the 2 folders it wouldn't make anything !! :idea:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
#Include <Array.au3>
If FileExists("data") Then
    Else
    DirCreate("data")
EndIf
#Region ### START Koda GUI section ### Form=c:\users\el-zaeem\desktop\backup\bacckup form.kxf
$Form1_1 = GUICreate("Z - Backup", 607, 560, 230, 132)
$Group1 = GUICtrlCreateGroup("", 8, 8, 585, 201)
$path_source = GUICtrlCreateInput("", 72, 43, 497, 21)
$browes_source = GUICtrlCreateButton("Browse", 16, 40, 49, 25, $WS_GROUP)
$Browes_b_dir = GUICtrlCreateButton("Browse", 17, 131, 49, 25, $WS_GROUP)
$path_b_dir = GUICtrlCreateInput("", 73, 134, 497, 21)
$icon = GUICtrlCreateButton("", 17, 160, 49, 41, $WS_GROUP)
$add = GUICtrlCreateButton("Add", 496, 168, 73, 25, $WS_GROUP)
$folder_to_b = GUICtrlCreateButton("Browse", 17, 86, 49, 25, $WS_GROUP)
$F2p_path = GUICtrlCreateInput("", 73, 89, 497, 21)
$Label3 = GUICtrlCreateLabel("Application dire", 17, 24, 76, 17)
$Label4 = GUICtrlCreateLabel("Folder to backup", 17, 69, 84, 17)
$Label5 = GUICtrlCreateLabel("Backup dir", 16, 114, 55, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup(" Options ", 8, 216, 585, 57)
$Checkbox1 = GUICtrlCreateCheckbox("Start lancher on computer startup", 24, 240, 177, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$List1 = GUICtrlCreateList("", 8, 304, 585, 201)
$Label1 = GUICtrlCreateLabel("Application  List", 9, 280, 95, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$ok = GUICtrlCreateButton("ok", 500, 518, 81, 25, $WS_GROUP)
$Delete = GUICtrlCreateButton("Delete", 400, 518, 81, 25, $WS_GROUP)
$list_icon = GUICtrlCreateButton("", 8, 510, 49, 41, $WS_GROUP)
$restore = GUICtrlCreateButton("Restore", 100, 518, 81, 25, $WS_GROUP)
$edit = GUICtrlCreateButton("Edit", 300, 518, 81, 25, $WS_GROUP)
$backup = GUICtrlCreateButton("backup", 200, 518, 81, 25, $WS_GROUP)
$Label2 = GUICtrlCreateLabel("Made by Elzaem", 512, 280, 82, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        case $browes_source
            $file = FileOpenDialog("Select file", @ProgramFilesDir & "", "Application (*.exe)", 1 + 4 )
            If @error Then
                GUICtrlSetData($path_source,"")
            Else
                $iconfile_to_use = $file
                $array = StringSplit($iconfile_to_use, '\', 1)
                $name = $array[$array[0]]
                $newname = StringReplace($name,".exe","")
                $hImage = _GUIImageList_Create(32, 32, 5, 3, 6)
                _GUIImageList_AddIcon($hImage, $iconfile_to_use, 0, True)
                _GUICtrlButton_SetImageList($icon, $hImage,4)
                GUICtrlSetData($path_source,$file)
            EndIf
        case $folder_to_b
            $var = FileSelectFolder("Choose a folder.", "")
            if $var = "" Then
            GUICtrlSetData($F2p_path,"")
            EndIf
            GUICtrlSetData($F2p_path,$var)
        case $Browes_b_dir
            $var2 = FileSelectFolder("Choose a folder.", "")
            if $var2 = "" Then
                GUICtrlSetData($path_b_dir,"")
            EndIf
            GUICtrlSetData($path_b_dir,$var2)
        case $add
            if GUICtrlRead($path_source) = "" or GUICtrlRead($F2p_path) = "" or GUICtrlRead($path_b_dir) = "" Then
            MsgBox("Error","Notic","Please choose  backup and restore folders")
            Else
            $array = StringSplit(GUICtrlRead($path_source), '\', 1)
            $name = $array[$array[0]]
            $newname = StringReplace($name,".exe","")
            IniWrite("data\" & $newname & ".ini","info","name",$name)
            IniWrite("data\" & $newname & ".ini","info","source",GUICtrlRead($path_source))
            IniWrite("data\" & $newname & ".ini","info","surcedir",GUICtrlRead($F2p_path))
            IniWrite("data\" & $newname & ".ini","info","backupdir",GUICtrlRead($path_b_dir))
            MsgBox("","","done")
            EndIf
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites
taietel

 Try this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
#Include <Array.au3>
If FileExists(@ScriptDir & "\data") Then
    Else
    DirCreate(@ScriptDir & "\data")
EndIf
#Region ### START Koda GUI section ### Form=c:\users\el-zaeem\desktop\backup\bacckup form.kxf
$Form1_1 = GUICreate("Z - Backup", 607, 560, 230, 132)
$Group1 = GUICtrlCreateGroup("", 8, 8, 585, 201)
$path_source = GUICtrlCreateInput("", 72, 43, 497, 21)
$browes_source = GUICtrlCreateButton("Browse", 16, 40, 49, 25, $WS_GROUP)
$Browes_b_dir = GUICtrlCreateButton("Browse", 17, 131, 49, 25, $WS_GROUP)
$path_b_dir = GUICtrlCreateInput("", 73, 134, 497, 21)
$icon = GUICtrlCreateButton("", 17, 160, 49, 41, $WS_GROUP)
$add = GUICtrlCreateButton("Add", 496, 168, 73, 25, $WS_GROUP)
$folder_to_b = GUICtrlCreateButton("Browse", 17, 86, 49, 25, $WS_GROUP)
$F2p_path = GUICtrlCreateInput("", 73, 89, 497, 21)
$Label3 = GUICtrlCreateLabel("Application dire", 17, 24, 76, 17)
$Label4 = GUICtrlCreateLabel("Folder to backup", 17, 69, 84, 17)
$Label5 = GUICtrlCreateLabel("Backup dir", 16, 114, 55, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup(" Options ", 8, 216, 585, 57)
$Checkbox1 = GUICtrlCreateCheckbox("Start lancher on computer startup", 24, 240, 177, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$List1 = GUICtrlCreateList("", 8, 304, 585, 201)
$Label1 = GUICtrlCreateLabel("Application  List", 9, 280, 95, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$ok = GUICtrlCreateButton("ok", 500, 518, 81, 25, $WS_GROUP)
$Delete = GUICtrlCreateButton("Delete", 400, 518, 81, 25, $WS_GROUP)
$list_icon = GUICtrlCreateButton("", 8, 510, 49, 41, $WS_GROUP)
$restore = GUICtrlCreateButton("Restore", 100, 518, 81, 25, $WS_GROUP)
$edit = GUICtrlCreateButton("Edit", 300, 518, 81, 25, $WS_GROUP)
$backup = GUICtrlCreateButton("backup", 200, 518, 81, 25, $WS_GROUP)
$Label2 = GUICtrlCreateLabel("Made by Elzaem", 512, 280, 82, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        case $browes_source
            $file = FileOpenDialog("Select file", @ProgramFilesDir & "", "Application (*.exe)", 1 + 4 )
            If @error Then
                GUICtrlSetData($path_source,"")
            Else
                $iconfile_to_use = $file
                $array = StringSplit($iconfile_to_use, '\', 1)
                $name = $array[$array[0]]
                $newname = StringReplace($name,".exe","")
                $hImage = _GUIImageList_Create(32, 32, 5, 3, 6)
                _GUIImageList_AddIcon($hImage, $iconfile_to_use, 0, True)
                _GUICtrlButton_SetImageList($icon, $hImage,4)
                GUICtrlSetData($path_source,$file)
            EndIf
        case $folder_to_b
            $var = FileSelectFolder("Choose a folder.", "")
            if $var = "" Then
            GUICtrlSetData($F2p_path,"")
            EndIf
            GUICtrlSetData($F2p_path,$var)
        case $Browes_b_dir
            $var2 = FileSelectFolder("Choose a folder.", "")
            if $var2 = "" Then
                GUICtrlSetData($path_b_dir,"")
            EndIf
            GUICtrlSetData($path_b_dir,$var2)
        case $add
            if GUICtrlRead($path_source) = "" or GUICtrlRead($F2p_path) = "" or GUICtrlRead($path_b_dir) = "" Then
            MsgBox("Error","Notic","Please choose  backup and restore folders")
            Else
            $array = StringSplit(GUICtrlRead($path_source), '\', 1)
            $name = $array[$array[0]]
            $newname = StringReplace($name,".exe","")
            IniWrite(@ScriptDir & "\data\" & $newname & ".ini","info","name",$name)
            IniWrite(@ScriptDir & "\data\" & $newname & ".ini","info","source",GUICtrlRead($path_source))
            IniWrite(@ScriptDir & "\data\" & $newname & ".ini","info","surcedir",GUICtrlRead($F2p_path))
            IniWrite(@ScriptDir & "\data\" & $newname & ".ini","info","backupdir",GUICtrlRead($path_b_dir))
            MsgBox(64,"Z - Backup","All done!")
            EndIf
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Edited by taietel

Share this post


Link to post
Share on other sites
ahmed9100

thx guys :idea: it works :(

but it's a weird thing right ! :)

Share this post


Link to post
Share on other sites
ResNullius

Hello every body whats wrong with my code !!

when i write any thing with my hand and press add it create the "ini" file in data folder :)

but

when i choose the file and the 2 folders it wouldn't make anything !! :idea:

Frome the Remarks in the help file for FileOpenDialog():

@WorkingDir is changed on successful return.

You can prove that to yourself by checking the value of @WorkingDir before and after the FileOpenDialog().

So, you're trying to save the ini in the (probably) non-existant "data" folder in the folder where you selected your exe.

That probably gives you enough info to solve your problem, right?

Share this post


Link to post
Share on other sites
Mungo

Frome the Remarks in the help file for FileOpenDialog():

You can prove that to yourself by checking the value of @WorkingDir before and after the FileOpenDialog().

So, you're trying to save the ini in the (probably) non-existant "data" folder in the folder where you selected your exe.

That probably gives you enough info to solve your problem, right?

I ran into then same problem - luckily found the post - however, is there a way to reset the @WorkingDir value again after the FileOpenDialog() e.g. through @ScriptDir value ?

Thanks

Share this post


Link to post
Share on other sites
Melba23

Mungo,

is there a way to reset the @WorkingDir value

From the Help file:

FileChangeDir - Changes the current working directory.

So you would need to use: :mellow:

FileChangeDir(@ScriptDir))

And you are back in the script folder again. :P

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
ResNullius

Mungo,

You could also make it so that you always uses @Scriptdir when referencing your inifile, as in IniWrite(@ScriptDir & "\myIniFile.ini",.....

That way you never have to worry about whether you've changed the working dir or not.

Share this post


Link to post
Share on other sites
Mungo

Mungo,

You could also make it so that you always uses @Scriptdir when referencing your inifile, as in IniWrite(@ScriptDir & "\myIniFile.ini",.....

That way you never have to worry about whether you've changed the working dir or not.

M23 and ResNullius,

Thanks, and done exactly as you said. Wasn't aware that the @workingdir value actually changes ... well, learned something new again :mellow: . I had also quite a few icon and gif files included in my script and they didn't show as well ... It works now, thanks. :P

Mungo

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  

×