cette procedure permet d'archiver tous les éléments sélectionnés dans la Explorerlist mais là ça rate quelques uns(surtout les fichiers)
Code : Tout sélectionner
;Auteur: SpaceMan
;version: Démo
;librairie utilisée: pureZip de (gnozal)
;{- Enumerations
;{ Windows
Enumeration
#Window_0
#Window_2
#Progression
EndEnumeration
;}
;{ Menu bars
Enumeration
#Menu_Window_0
EndEnumeration
;{ Menu items
Enumeration
#Menu_Window_0_0_ExtraireUneArchive
#Menu_Window_0_0_OuvrirUneArchive
#Menu_Window_0_1_TesterUneArchive
#Menu_Window_0_2_MotDePasse
#Menu_Window_0_3_Configuration
#Menu_Window_0_4_Quitter
#Menu_Window_0_5_Compresser
#Menu_Window_0_6_CompresserAvecPassword
#Menu_Window_0_7_Decompresser
#Menu_Window_0_8_SupprimerPassword
#Menu_Window_0_9_TutorialPCDEVZIP
#Menu_Window_0_10_Enregistrement
#Menu_Window_0_11_APropos
EndEnumeration
;}
;{ Status bars
Enumeration
#StatusBar_Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
#ExplorerComboGadget
#ExplorerList_1
#StatusBar
#compress
#decompress
#Text_10
#String_9
#Text_18
#String_17
#Button_12
#Frame3D_16
#Text_12
#ComboBox_13
#Text_14
#ComboBox_15
#Frame3DGadget_245
#TextGadget_244
#StringGadget_246
#TextGadget_243
#StringGadget_247
#CheckBoxGadget_242
#CheckBoxGadget_241
#ButtonGadget_240
#ButtonGadget_239
#Button_4
EndEnumeration
Global Disk$
Disk$ = "C:\"
Global Window_0, ProgressBar_Compression, Text_FileProcessed, Text_1, ProgressBar_Progression
Global nom_archive.s,destination$,pwd$,pwd2$, repfichier$
;}
Procedure OpenWindow_Window_0()
If OpenWindow(#Window_0, 170, 90, 652, 470, "PC&DEV Compressor", #PB_Window_SystemMenu|#PB_Window_TitleBar|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SmartWindowRefresh(#Window_0, 1)
CreateGadgetList(WindowID(#Window_0))
If CreateMenu(#Menu_Window_0, WindowID(#Window_0))
MenuTitle("Menu")
MenuItem(#Menu_Window_0_0_OuvrirUneArchive,"Ouvrir Archive")
MenuItem(#Menu_Window_0_0_ExtraireUneArchive, "Extraire Archive")
MenuItem(#Menu_Window_0_1_TesterUneArchive, "Tester Archive")
MenuItem(#Menu_Window_0_3_Configuration, "Configuration")
MenuBar()
MenuItem(#Menu_Window_0_4_Quitter, "Quitter")
MenuTitle("Commandes")
;MenuItem(#Menu_Window_0_12_Compresser, "Compresser")
MenuItem(#Menu_Window_0_5_Compresser, "Compresser")
MenuItem(#Menu_Window_0_6_CompresserAvecPassword, "Compresser avec Password")
MenuBar()
MenuItem(#Menu_Window_0_7_Decompresser, "Décompresser")
MenuItem(#Menu_Window_0_8_SupprimerPassword, "Supprimer Password")
MenuTitle("Aide")
MenuItem(#Menu_Window_0_9_TutorialPCDEVZIP, "Tutorial(PC-DEV ZIP)")
MenuItem(#Menu_Window_0_10_Enregistrement, "Enregistrement")
MenuItem(#Menu_Window_0_11_APropos, "A Propos")
ExplorerComboGadget(#ExplorerComboGadget, 1, 02, 650, 200, Disk$, #PB_Explorer_Editable)
ExplorerListGadget(#ExplorerList_1, 0, 25, 651, 405, Disk$, #PB_Explorer_MultiSelect|#PB_Explorer_AutoSort|#PB_Explorer_AlwaysShowSelection|#PB_Explorer_FullRowSelect)
SetGadgetItemAttribute(#ExplorerList_1, 0,#PB_Explorer_ColumnWidth, 347)
; Gadget Resizing
PureRESIZE_SetGadgetResize(#ExplorerList_1, 1, 1, 1, 1)
PureRESIZE_SetGadgetResize(#ExplorerComboGadget, 1, 1, 1, 1)
EndIf
EndIf
EndProcedure
Procedure OpenWindow_Archive()
If OpenWindow(#Window_2, 587, 257, 353, 350, "Ajouter Archive", #PB_Window_SystemMenu|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
SmartWindowRefresh(#Window_2, 1)
StickyWindow(#Window_2, 1)
If CreateGadgetList(WindowID(#Window_2))
TextGadget(#Text_10, 7, 21, 80, 15, "Nom de l'archive")
StringGadget(#String_9, 92, 16, 221, 20, "")
TextGadget(#Text_18, 8, 55, 65, 15, "Emplacement")
StringGadget(#String_17, 92, 50, 220, 20, "")
ButtonGadget(#Button_12, 318, 51, 25, 20, "...")
Frame3DGadget(#Frame3D_16, 10, 85, 330, 85, "Option de Compression")
TextGadget(#Text_12, 25, 105, 90, 15, "Format de l'archive")
ComboBoxGadget(#ComboBox_13, 220, 100, 105, 100):DisableGadget(#ComboBox_13,1)
AddGadgetItem(#ComboBox_13, 0, "Zip")
AddGadgetItem(#ComboBox_13, 1, "Arj")
AddGadgetItem(#ComboBox_13, 2, "Ace")
SetGadgetState(#ComboBox_13, 0)
TextGadget(#Text_14, 25, 135, 110, 15, "Type de compresssion")
ComboBoxGadget(#ComboBox_15, 220, 135, 105, 100):DisableGadget(#ComboBox_15,1)
AddGadgetItem(#ComboBox_15, 0, "Normal")
AddGadgetItem(#ComboBox_15, 1, "Deflate")
SetGadgetState(#ComboBox_15, 0)
Frame3DGadget(#Frame3DGadget_245, 10, 182, 330, 135, "Mot de Passe")
TextGadget(#TextGadget_244, 20, 200, 118, 15, "Entrer le mot de passe")
StringGadget(#StringGadget_246, 165, 235, 160, 20, "", #PB_String_Password)
TextGadget(#TextGadget_243, 20, 240, 128, 15, "Confirmer le mot de passe")
StringGadget(#StringGadget_247, 165, 199, 160, 20, "", #PB_String_Password)
CheckBoxGadget(#CheckBoxGadget_242, 20, 269, 140, 15, "Afficher le mot de Passe")
CheckBoxGadget(#CheckBoxGadget_241, 20, 294, 180, 15, "Crypter le nom des fichiers"):DisableGadget(#CheckBoxGadget_241,1)
ButtonGadget(#ButtonGadget_240, 218, 324, 60, 20, "OK")
ButtonGadget(#ButtonGadget_239, 288, 325, 54, 19, "Annuler")
EndIf
EndIf
EndProcedure
Procedure Open_Window()
Window_0 = OpenWindow(#PB_Any, 382, 285, 315, 128, "Compressor",#PB_Window_TitleBar | #PB_Window_ScreenCentered)
If Window_0 : StickyWindow(Window_0, 1)
If CreateGadgetList(WindowID(Window_0))
ProgressBar_Compression = ProgressBarGadget(#PB_Any, 5, 25, 305, 20, 0, 100)
Text_FileProcessed = TextGadget(#PB_Any, 74, 4, 150, 15, "Extraction des fichiers...", #PB_Text_Center)
Text_1 = TextGadget(#PB_Any, 100, 58, 100, 15, "Progression...", #PB_Text_Center)
ProgressBar_Progression = ProgressBarGadget(#PB_Any, 5, 77, 305, 20, 0, 100)
ButtonGadget(#Button_4, 240, 106, 70, 18, "Annuler")
EndIf
EndIf
EndProcedure
Procedure Close_Window()
CloseWindow(Window_0)
EndProcedure
Procedure PureZIP_CallbackC(File.s, PerCent.f)
SetGadgetText(Text_FileProcessed, GetFilePart(File))
SetGadgetState(ProgressBar_Compression, PerCent.f)
While WindowEvent() : Wend
EndProcedure
Procedure PureZIP_CallbackP(File.s, PerCent.f)
SetGadgetState(ProgressBar_Progression, PerCent.f)
While WindowEvent() : Wend
EndProcedure
;
myFileinfo.PureZIP_FileInfo
PureZIP_SetProgressionCallback(@PureZIP_CallbackP())
PureZIP_SetCompressionCallback(@PureZIP_CallbackC())
Procedure CompresserArchive()
Protected i
If GetGadgetState(#ExplorerList_1) > -1
nom_archive$ = GetGadgetText(#String_9)
destination$ = GetGadgetText(#String_17)
If nom_archive$ And destination$ :CloseWindow(#Window_2)
For i = 0 To CountGadgetItems(#ExplorerList_1) - 1
If GetGadgetItemState(#ExplorerList_1, i) & #PB_Explorer_Selected ;un élément est sélectionné et c'est ...
If GetGadgetItemState(#ExplorerList_1, i) & #PB_Explorer_File ; ... un fichier
PureZIP_Archive_Create(destination$+nom_archive$, #APPEND_STATUS_CREATE)
Debug GetGadgetItemText(#ExplorerList_1, i, 0) + " est sélectionné et c'est un fichier"
PureZIP_AddFiles(destination$+nom_archive$,GetGadgetText(#ExplorerList_1) + GetGadgetItemText(#ExplorerList_1, i, 0), #PureZIP_StorePathRelative ,#PureZIP_NotRecursive)
ElseIf GetGadgetItemState(#ExplorerList_1, i) & #PB_Explorer_Directory ; ... un répertoire
Debug GetGadgetItemText(#ExplorerList_1, i, 0) + " est sélectionné et c'est un dossier"
PureZIP_AddFiles(destination$+nom_archive$,GetGadgetText(#ExplorerList_1) + GetGadgetItemText(#ExplorerList_1, i, 0)+"\" + "*.*", #PureZIP_StorePathRelative ,#PureZIP_Recursive)
EndIf: EndIf
Next
Else
MessageRequester("Compressor","Véririfier le nom et la destination de l'archive !",#MB_ICONERROR)
EndIf
Else
MessageRequester("Compressor","Veuillez selectionnez les fichiers !",#MB_ICONERROR)
EndIf
EndProcedure
Procedure statusbar1()
Protected Nombre_Elements
Nombre_Elements = CountGadgetItems(#ExplorerList_1)
If CreateStatusBar(#StatusBar_Window_0, WindowID(#Window_0))
AddStatusBarField(175)
AddStatusBarField(480)
StatusBarText(#StatusBar_Window_0,0, Str(Nombre_Elements) + " "+"élément(s)")
EndIf
EndProcedure
OpenWindow_Window_0()
statusbar1()
Repeat
Select WaitWindowEvent()
; ///////////////////
Case #PB_Event_Menu
Select EventMenu()
Case #Menu_Window_0_5_Compresser
If GetGadgetState(#ExplorerList_1) > -1
OpenWindow_Archive() : SetGadgetText(#String_9,"Archive.zip")
Else:MessageRequester("Compressor","Veuillez selectionnez les fichiers !",#MB_ICONERROR)
EndIf
Case #Menu_Window_0_7_Decompresser
Case #Menu_Window_0_0_ExtraireUneArchive
Case #Menu_Window_0_0_OuvrirUneArchive
Case #Menu_Window_0_1_TesterUneArchive
Case #Menu_Window_0_2_MotDePasse:
Case #Menu_Window_0_3_Configuration
Case #Menu_Window_0_4_Quitter:Break
EndSelect
; //////////////////////
Case #PB_Event_Gadget
EventGadget = EventGadget()
EventType = EventType()
Select EventGadget()
Case #ExplorerComboGadget
SetGadgetText(#ExplorerList_1, GetGadgetText(#ExplorerComboGadget))
If EventType() = #PB_EventType_Change
Nombre_Elements = CountGadgetItems(#ExplorerList_1)
StatusBarText(#StatusBar_Window_0,0, Str(Nombre_Elements) + " élément(s)") :EndIf
Case #ButtonGadget_239
CloseWindow(#Window_2)
Case #ButtonGadget_240
nom_archive$ = GetGadgetText(#String_9)
destination$ = GetGadgetText(#String_17)
pwd$ = GetGadgetText(#StringGadget_246)
pwd2$ = GetGadgetText(#StringGadget_246)
If nom_archive$ <> "" And destination$ <> "" And pwd$ = pwd2$ And pwd$ = "" And pwd2$ = ""
SetWindowState(#Window_0,#PB_Window_Minimize)
Open_Window()
CompresserArchive():Close_Window() :SetWindowState(#Window_0,#PB_Window_Normal)
EndIf
Case #ExplorerList_1
If EventType() = #PB_EventType_LeftDoubleClick
SetGadgetText(#ExplorerComboGadget,GetGadgetText(#ExplorerList_1)): EndIf
compteur_dossier=0
compteur_fichier=0
last_element=CountGadgetItems(#ExplorerList_1)-1
For position_element=0 To last_element
etat_gadget=GetGadgetItemState(#ExplorerList_1,position_element)
If etat_gadget & #PB_Explorer_Selected
If etat_gadget & #PB_Explorer_File
compteur_fichier+1
Else
If position_element=0
If GetGadgetItemText(#ExplorerList_1,0,0)=".." ; Pour ne pas compter le .. comme dossier
compteur_dossier-1
EndIf
EndIf
compteur_dossier+1
EndIf
EndIf
Next position_element
StatusBarText(#StatusBar_Window_0,1, Str(compteur_dossier)+" dossier(s) "+Str(compteur_fichier)+" fichier(s)"+" sélectionné(s)")
EndSelect
; //////////////////////
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = #Window_0
Break
ElseIf EventWindow = #Window_2
CloseWindow(#Window_2)
EndIf
EndSelect
ForEver