
SetupMain.pb
Code : Tout sélectionner
; PureBasic Visual Designer v3.90 build 1360
DataSection
PackStart:
IncludeBinary "Setup.pak"
PackEnd:
EndDataSection
IncludeFile "SetupInclude.pb"
repsetup$ = ApplicationDir()
If FileSize(repsetup$+"Client.exe") = -1
Open_Window_1()
RepTemp$ = GetTempDir()
If CreateIncludeFile(RepTemp$+"Setup.pak", ?PackStart, ?PackEnd) = 0
MessageRequester("Error", "Can't create temp file !", #MB_ICONERROR)
End
Else
If OpenPack(RepTemp$+"Setup.pak")
NextFile = NextPackFile()
While NextFile
FileName$ = PeekS(NextFile)
NextFile = NextPackFile()
NextFileSize = PackFileSize()
CreateFile(100, RepTemp$+FileName$)
WriteData(NextFile, NextFileSize)
CloseFile(100)
AddElement(Files())
Files()\Name = FileName$
NextFile = NextPackFile()
Wend
ClosePack()
Else
MessageRequester("Error", "Can't create temp file !", #MB_ICONERROR)
DeleteFile(RepTemp$+"Setup.pak")
End
EndIf
EndIf
DeleteFile(RepTemp$+"Setup.pak")
CloseWindow(#Window_1)
Open_Window_0()
SNext = 0
Boucle:
Repeat
Delay(1)
If IsGadget(#optionyes) And SNext
If GetGadgetState(#optionyes) = 1
DisableGadget(#Suivant1, 0)
Else
DisableGadget(#Suivant1, 1)
EndIf
EndIf
Event = WindowEvent()
If Event = #PB_EventGadget
;Debug "WindowID: " + Str(EventWindowID())
GadgetID = EventGadgetID()
If GadgetID = #Annuler
rep = MessageRequester("Caution", "Do you want to abort Bird Chat install ?", #MB_ICONWARNING | #PB_MessageRequester_YesNo)
If rep = 6
DeleteFile(RepTemp$+"Client.exe")
DeleteFile(RepTemp$+"Client.exe.manifest")
DeleteFile(RepTemp$+"ClientInclude.pb")
DeleteFile(RepTemp$+"ClientMain.pb")
DeleteFile(RepTemp$+"changelog.txt")
DeleteFile(RepTemp$+"Bird.wav")
End
EndIf
ElseIf GadgetID = #Suivant1
Select SNext
Case 0
FreeGadget(#Gauche)
FreeGadget(#Install)
FreeGadget(#Container)
HideGadget(#Haut, 0)
HideGadget(#license, 0)
HideGadget(#licensetxt, 0)
HideGadget(#optionyes, 0)
HideGadget(#optionno, 0)
HideGadget(#Barre1,0)
DisableGadget(#Suivant1, 1)
AddGadgetItem(#license, -1, "This client Bird Chat is under GPL. That mind it's free and you can modify it."+Chr(13)+Chr(10)+"Designed by Heis Spiter.")
Case 1
FreeGadget(#license)
FreeGadget(#licensetxt)
FreeGadget(#optionyes)
FreeGadget(#optionno)
HideGadget(#reptxt, 0)
HideGadget(#reptype, 0)
Case 2
repins$ = GetGadgetText(#reptype)
If repins$ = ""
SNext = SNext-1
MessageRequester("Error", "Enter a directory !", #MB_ICONERROR)
Else
FreeGadget(#reptxt)
FreeGadget(#reptype)
HideGadget(#repdemtxt, 0)
HideGadget(#repdemtype, 0)
If Right(repins$, 1) <> "\"
repins$ = repins$+"\"
EndIf
EndIf
Case 3
Men$ = GetGadgetText(#repdemtype)
FreeGadget(#repdemtxt)
FreeGadget(#repdemtype)
If Men$ <> ""
Programs$ = GetSpecialDirectory(02)
If Right(Men$, 1) <> "\"
Men$ = Men$+"\"
EndIf
MenD$ = Programs$+Men$
EndIf
HideGadget(#Installtxt, 0)
HideGadget(#installprog, 0)
HideGadget(#installlist, 0)
SetGadgetText(#Installtxt, "Creating directory : "+repins$)
If CreateDirectory(repins$) = 0
RepUp = FileSize(repins$)
If RepUp = -2
Update = MessageRequester("Question", "A previous version has been found. Do you want to update ?", #MB_ICONQUESTION | #PB_MessageRequester_YesNo)
If Update = 6
DeleteFile(repins$+"Client.exe")
DeleteFile(repins$+"ClientMain.pb")
DeleteFile(repins$+"ClientInclude.pb")
DeleteFile(repins$+"Changelog.txt")
DeleteFile(repins$+"Unins.exe")
DeleteFile(repins$+"Bird.wav")
Else
End
EndIf
Else
MessageRequester("Error", "Can't create directory "+repins$, #MB_ICONERROR)
End
EndIf
Else
AddGadgetItem(#installlist, -1, "Creating directory : "+repins$)
SetGadgetState(#installprog, 10)
EndIf
NbFiles = CountList(Files())
NbTotal = NbFiles + 1
If Update <> 6
NbTotal = NbTotal + 1
EndIf
Percent = 100 / NbTotal
ResetList(Files())
For k = 1 To NbFiles
NextElement(Files())
SetGadgetText(#Installtxt, "Copying : "+Files()\Name)
If CopyFile(RepTemp$+Files()\Name, repins$+Files()\Name) = 0
MessageRequester("Error", "Can't copy "+Files()\Name, #MB_ICONERROR)
DeleteDirectory(repins$, "*.*", #PB_FileSystem_Recursive | #PB_FileSystem_Force)
ResetList(Files())
While NextElement(Files())
DeleteFile(RepTemp$+Files()\Name)
Wend
End
Else
AddGadgetItem(#installlist, -1, "Copying : "+Files()\Name)
SetGadgetState(#installprog, GetGadgetState(#installprog)+Percent)
DeleteFile(RepTemp$+Files()\Name)
EndIf
Next k
SetGadgetText(#Installtxt, "Creating uninstaller")
If CopyFile(GetExeName(), repins$+"Unins.exe") = 0
MessageRequester("Error", "Can't create uninstaller", #MB_ICONERROR)
End
EndIf
AddGadgetItem(#installlist, -1, "Creating uninstaller")
If Update <> 6
If MenD$ <> ""
SetGadgetText(#Installtxt, "Creating directory : "+MenD$)
If CreateDirectory(MenD$) = 0
MessageRequester("Error", "Can't create directory "+MenD$, #MB_ICONERROR)
DeleteDirectory(repins$, "*.*", #PB_FileSystem_Recursive | #PB_FileSystem_Force)
End
EndIf
AddGadgetItem(#installlist, -1, "Creating directory : "+MenD$)
SetGadgetText(#Installtxt, "Creating shortcut")
If CreateShellLink(repins$+"Client.exe", MenD$+"Bird Chat Client.lnk", "", "Launch Bird Chat Client", repins$, #SW_SHOWNORMAL, 0, "", 0) = 0
MessageRequester("Error", "Can't create shortcut")
DeleteDirectory(repins$, "*.*", #PB_FileSystem_Recursive | #PB_FileSystem_Force)
DeleteDirectory(MenD$, "*.*", #PB_FileSystem_Recursive | #PB_FileSystem_Force)
End
EndIf
AddGadgetItem(#installlist, -1, "Creating shortcut")
SetGadgetText(#Installtxt, "Creating shortcut for uninstall")
If CreateShellLink(repins$+"Unins.exe", MenD$+"Uninstall.lnk", "", "Uninstall Bird Chat Client", repins$, #SW_SHOWNORMAL, 0, "", 0) = 0
MessageRequester("Error", "Can't create shortcut for uninstall")
DeleteDirectory(repins$, "*.*", #PB_FileSystem_Recursive | #PB_FileSystem_Force)
DeleteDirectory(MenD$, "*.*", #PB_FileSystem_Recursive | #PB_FileSystem_Force)
End
EndIf
AddGadgetItem(#installlist, -1, "Creating shortcut for uninstall")
SetGadgetState(#installprog, 100)
EndIf
AddGadgetItem(#installlist, -1, "Install finished")
SetGadgetText(#Installtxt, "Install finished")
If CreateFile(2, repins$+"Install.log")
WriteStringN(repins$)
WriteString(MenD$)
Else
MessageRequester("Error", "Can't write install log", #MB_ICONERROR)
EndIf
Launch = MessageRequester("Information", "Install finished. Do you want to launch Bird Chat Client ?", #MB_ICONQUESTION | #PB_MessageRequester_YesNo)
If Launch = 7
End
ElseIf Launch = 6
RunProgram(repins$+"Client.exe")
quit = 1
EndIf
Else
SetGadgetState(#installprog, 100)
SetGadgetText(#Installtxt, "Update finished")
AddGadgetItem(#installlist, -1, "Update finished")
Launch = MessageRequester("Information", "Update finished. Do you want to launch Bird Chat Client ?", #MB_ICONQUESTION | #PB_MessageRequester_YesNo)
If Launch = 7
End
ElseIf Launch = 6
RunProgram(repins$+"Client.exe")
quit = 1
EndIf
EndIf
EndSelect
SNext=SNext+1
EndIf
EndIf
Until Event = #PB_EventCloseWindow Or quit = 1
If Event = #PB_EventCloseWindow
rep = MessageRequester("Caution", "Do you want to abort Bird Chat install ?", #MB_ICONWARNING | #PB_MessageRequester_YesNo)
If rep = 6
ResetList(Files())
While NextElement(Files())
DeleteFile(RepTemp$+Files()\Name)
Wend
End
ElseIf rep = 7
Goto Boucle
EndIf
Else
End
EndIf
Else
ResetList(Files())
While NextElement(Files())
DeleteFile(RepTemp$+Files()\Name)
Wend
Unins = MessageRequester("Question", "Do you want to uninstall Bird Chat Client ?", #MB_ICONQUESTION | #PB_MessageRequester_YesNo)
If Unins = 7
End
ElseIf Unins = 6
If ReadFile(3, "install.log") = 0
MessageRequester("Error", "Can't read uninstall informations !", #MB_ICONERROR)
End
Else
logrep$ = ReadString()
logmenu$ = ReadString()
CloseFile(3)
DeleteFile(logrep$+"install.log")
EndIf
Config = MessageRequester("Question", "Do you want to keep configuration ?", #MB_ICONQUESTION | #PB_MessageRequester_YesNo)
DeleteFile(logrep$+"Client.exe")
DeleteFile(logrep$+"ClientMain.pb")
DeleteFile(logrep$+"ClientInclude.pb")
DeleteFile(logrep$+"Changelog.txt")
DeleteFile(logrep$+"Client.exe.manifest")
DeleteFile(logrep$+"servers.ser")
DeleteFile(logrep$+"Bird.wav")
DeleteFile(logrep$+"lang.lng")
If Config = 7
DeleteFile(logrep$+"servers.list")
EndIf
DeleteFile(logmenu$+"Bird Chat Client.lnk")
DeleteFile(logmenu$+"Uninstall.lnk")
DeleteDirectory(logmenu$, "*.*")
If CreateFile(1, "C:\birdchat.bat")
WriteStringN("@echo off")
WriteStringN(":loop")
WriteStringN("del "+Chr(34)+GetExeName()+Chr(34))
WriteStringN("if exist "+Chr(34)+GetExeName()+Chr(34)+" goto loop")
If config = 7
WriteStringN("rd "+Chr(34)+repsetup$+Chr(34))
EndIf
WriteString("del C:\birdchat.bat")
CloseFile(1)
RunProgram("C:\birdchat.bat", "", "C:\", 2)
MessageRequester("Information", "Uninstall finished.", #MB_ICONINFORMATION)
Else
MessageRequester("Information", "Uninstall finished. Delete Bird Chat Client directory "+repsetup$, #MB_ICONINFORMATION)
EndIf
EndIf
EndIf
End
SetupInclude
Code : Tout sélectionner
; PureBasic Visual Designer v3.90 build 1360
;- Window Constants
;
Enumeration
#Window_0
#Window_1
EndEnumeration
;- Police Constants
;
Enumeration
#Titre
#Texte
EndEnumeration
;- Gadget Constants
;
Enumeration
#Extract
#ExProg
#Container
#Install
#ImageInstall
#Barre2
#Barre1
#Gauche
#Annuler
#Suivant1
#Suivant2
#Haut
#license
#licensetxt
#optionyes
#optionno
#reptxt
#reptype
#repdemtxt
#repdemtype
#Installtxt
#installprog
#installlist
EndEnumeration
;- Image Plugins
;- Image Globals
Global Image0, Image1
;- Catch Images
Image0 = CatchImage(0, ?Image0)
Image1 = CatchImage(1, ?Image1)
;- Images
DataSection
Image0:
IncludeBinary "gauche.bmp"
Image1:
IncludeBinary "haut.bmp"
EndDataSection
Structure Files
Name.s
EndStructure
NewList Files.Files()
Procedure Open_Window_1()
If OpenWindow(#Window_1, 353, 360, 150, 50, #PB_Window_ScreenCentered, "Please wait...")
If CreateGadgetList(WindowID())
TextGadget(#Extract, 10, 10, 130, 20, "Please wait...")
TextGadget(#ExProg, 10, 30, 130, 20, "Preparing install...")
EndIf
EndIf
EndProcedure
Declare.s GetSpecialDirectory(ID)
Procedure Open_Window_0()
If OpenWindow(#Window_0, 298, 148, 502, 369, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "Installation")
If CreateGadgetList(WindowID())
ContainerGadget(#Container, 164, 0, 338, 314)
If CreateImage(#ImageInstall, 338, 314)
If StartDrawing(ImageOutput())
DrawingFont(LoadFont(#Titre, "Arial", 16, #PB_Font_Bold))
Locate(0, 0)
DrawText("Welcome in the installation of ")
Locate(0, 24)
DrawText("Bird Chat ")
DrawingFont(LoadFont(#Texte, "Arial", 10))
Locate(0, 48)
DrawText("This wizard will help during the installaton of Bird Chat ")
Locate(0, 64)
DrawText("release 2.00 Client on you computer ")
For k = 80 To 314 Step 16
Locate(0, k)
DrawText(" ")
Next k
StopDrawing()
EndIf
EndIf
ImageGadget(#Install, 0, 0, 338, 314, UseImage(#ImageInstall))
EndIf
If CreateGadgetList(WindowID())
Frame3DGadget(#Barre1, - 5, -5, 530, 107, "")
Frame3DGadget(#Barre2, - 5, -5, 530, 319, "")
;TextGadget(#Barre2, 0, 300, 500, 15, "____________________________________________________________________________________")
ImageGadget(#Gauche, 0, 0, 164, 314, Image0)
ImageGadget(#Haut, 0, 0, 500, 100, Image1)
ButtonGadget(#Annuler, 412, 330, 73, 21, "Cancel")
ButtonGadget(#Suivant1, 322, 330, 73, 21, "&Next >")
EditorGadget(#license, 30, 130, 442, 140, "")
TextGadget(#licensetxt, 30, 110, 442, 20, "Read license :")
OptionGadget(#optionyes, 30, 275, 442, 15, "I agree")
OptionGadget(#optionno, 30, 290, 442, 15, "I don't agree")
TextGadget(#reptxt, 30, 110, 442, 20, "Choose directory where you want to install Bird Chat Client :")
; Program Files
PFiles$ = GetSpecialDirectory(38)
If PFiles$ = ""
; DeskTop
PFiles$ = Left(GetSpecialDirectory(00), 3)
EndIf
StringGadget(#reptype, 30, 150, 442, 20, PFiles$+"Bird Chat")
TextGadget(#repdemtxt, 30, 110, 442, 20, "Choose directory where you want to install shortcuts : (leave blank if not)")
StringGadget(#repdemtype, 30, 150, 442, 20, "\Bird Chat")
TextGadget(#Installtxt, 30, 110, 442, 20, "Installing")
ProgressBarGadget(#installprog, 30, 140, 442, 20, 0, 100, #PB_ProgressBar_Smooth)
ListViewGadget(#installlist, 30, 170, 442, 109)
HideGadget(#Haut, 1)
HideGadget(#Barre1,1)
HideGadget(#license, 1)
HideGadget(#licensetxt, 1)
HideGadget(#optionyes, 1)
HideGadget(#optionno, 1)
HideGadget(#reptxt, 1)
HideGadget(#reptype, 1)
HideGadget(#repdemtxt, 1)
HideGadget(#repdemtype, 1)
HideGadget(#Installtxt, 1)
HideGadget(#installprog, 1)
HideGadget(#installlist, 1)
SendMessage_(GadgetID(#license), #EM_SETREADONLY, #True, 0)
EndIf
EndIf
EndProcedure
#IncludeFile = 1
Procedure CreateIncludeFile(name.s, *StartFile, *EndFile)
If CreateFile(#IncludeFile, name)
WriteData(*StartFile, *EndFile - *StartFile)
CloseFile(#IncludeFile)
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
Procedure.s ApplicationDir()
appdir$ = Space(255)
GetCurrentDirectory_(255, @appdir$)
If Right(appdir$, 1) <> "\"
appdir$ = appdir$ + "\"
EndIf
ProcedureReturn appdir$
EndProcedure
Procedure.s GetTempDir()
Temp$ = Space(255)
GetTempPath_(255, Temp$)
If Right(Temp$, 1) <> "\"
Temp$ = Temp$ + "\"
EndIf
ProcedureReturn Temp$
EndProcedure
Procedure.s GetSpecialDirectory(ID)
SpecialDirectory$ = Space(260)
lngRet = SHGetSpecialFolderLocation_(0, ID, @pidl)
If lngRet = 0
SHGetPathFromIDList_(pidl, @SpecialDirectory$)
If lngRet = 0
SpecialDirectory$ = RTrim(SpecialDirectory$)
If Right(SpecialDirectory$, 1) <> "\"
SpecialDirectory$ = SpecialDirectory$ + "\"
EndIf
ProcedureReturn SpecialDirectory$
EndIf
CoTaskMemFree_(pidl)
EndIf
EndProcedure
Procedure.s GetExeName()
ExeName.s = Space(255)
GetModuleFileName_(0, @ExeName, 255)
ProcedureReturn ExeName
EndProcedure
Procedure CreateShellLink(PATH$, LINK$, Argument$, DESCRIPTION$, WorkingDirectory$, ShowCommand.l, HotKey.l, IconFile$, IconIndexInFile.l)
CoInitialize_(0)
If CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLink, @psl.IShellLinkA) = 0
Set_ShellLink_preferences :
psl\SetPath(@PATH$)
psl\SetArguments(@Argument$)
psl\SetWorkingDirectory(@WorkingDirectory$)
psl\SetDescription(@DESCRIPTION$)
psl\SetShowCmd(ShowCommand)
psl\SetHotkey(HotKey)
psl\SetIconLocation(@IconFile$, IconIndexInFile)
ShellLink_SAVE :
If psl\QueryInterface(?IID_IPersistFile, @ppf.IPersistFile) = 0
mem.s = Space(1000)
MultiByteToWideChar_(#CP_ACP, 0, LINK$, -1, mem, 1000)
hres = ppf\Save(@mem, #True)
result = 1
ppf\Release()
EndIf
psl\Release()
EndIf
CoUninitialize_()
ProcedureReturn result
DataSection
CLSID_ShellLink :
; 00021401-0000-0000-C000-000000000046
Data.l $00021401
Data.w $0000, $0000
Data.b $C0, $00, $00, $00, $00, $00, $00, $46
IID_IShellLink :
; DEFINE_SHLGUID(IID_IShellLinkA, 0x000214EEL, 0, 0);
; C000-000000000046
Data.l $000214EE
Data.w $0000, $0000
Data.b $C0, $00, $00, $00, $00, $00, $00, $46
IID_IPersistFile :
; 0000010b-0000-0000-C000-000000000046
Data.l $0000010B
Data.w $0000, $0000
Data.b $C0, $00, $00, $00, $00, $00, $00, $46
EndDataSection
EndProcedure

Et deux autres fichiers pas obligatoires, mais qui montrent comme se servir de l'install.
SetupPack
Code : Tout sélectionner
Procedure AddPackFileWithName(NomFichier$, NiveauCompression)
NomFichier$ = GetFilePart(NomFichier$)
AddPackMemory(@NomFichier$, Len(NomFichier$)+1)
ProcedureReturn AddPackFile(NomFichier$, NiveauCompression)
EndProcedure
If FileSize("Setup.pak") <> -1
DeleteFile("Setup.pak")
EndIf
avant = FileSize("Client.exe")+FileSize("Client.exe.manifest")+FileSize("ClientInclude.pb")+FileSize("ClientMain.pb")+FileSize("changelog.txt")
Debug avant/1024
RunProgram("D:\Site\www\dev\Chat\sources\upx.exe ", "--best "+Chr(34)+"D:\Site\www\dev\Chat\sources\Client.exe"+Chr(34), "", 1)
RunProgram("D:\Site\www\dev\Chat\sources\upx.exe ", "--best "+Chr(34)+"D:\Site\www\dev\Chat\sources\Server.exe"+Chr(34), "", 1)
Delay(2000)
avant = FileSize("Client.exe")+FileSize("Client.exe.manifest")+FileSize("ClientInclude.pb")+FileSize("ClientMain.pb")+FileSize("changelog.txt")
Debug avant/1024
If CreatePack("Setup.pak")
AddPackFileWithName("Client.exe", 9)
AddPackFileWithName("Client.exe.manifest", 9)
AddPackFileWithName("ClientInclude.pb", 9)
AddPackFileWithName("ClientMain.pb", 9)
AddPackFileWithName("SetupMain.pb", 9)
AddPackFileWithName("SetupInclude.pb", 9)
AddPackFileWithName("changelog.txt", 9)
AddPackFileWithName("Bird.wav", 9)
ClosePack()
EndIf
apres = FileSize("Setup.pak")
Debug apres/1024

Code : Tout sélectionner
OpenConsole()
PrintN("D"+Chr(130)+"claration des variables")
PBCompiler$ = "C:\Program Files\PureBasic\Compilers\PBCompiler.exe"
PrintN("PBCompiler$ = "+Chr(34)+"C:\Program Files\PureBasic\Compilers\PBCompiler.exe"+Chr(34))
Path$ = "D:\Site\www\dev\Chat\sources\"
PrintN("Path$ = "+Chr(34)+"D:\Site\www\dev\Chat\sources\"+Chr(34))
PrintN("D"+Chr(130)+"clar"+Chr(130))
PrintN("Lancement des compilations")
PrintN("RunProgram(PBCompiler$, Path$+"+Chr(34)+"SetupPack.pb /DEBUGGER"+Chr(34)+", "+Chr(34)+Chr(34)+", 1)")
RunProgram(PBCompiler$, Path$+"SetupPack.pb /DEBUGGER", "", 1)
PrintN("RunProgram("+Chr(34)+PBCompiler$+Chr(34)+", "+Chr(34)+Path$+"SetupPack.pb /DEBUGGER"+Chr(34)+", "+Chr(34)+Chr(34)+", 1)")
PrintN("Attente")
PrintN("Delay(10000)")
Delay(10000)
PrintN("Attendu")
PrintN("RunProgram(PBCompiler$, Path$+"+Chr(34)+"SetupMain.pb /EXE "+Chr(34)+"+Path$+"+Chr(34)+"Setup.exe /ICON "+Chr(34)+"+Path$+"+Chr(34)+"Setup.ico"+Chr(34)+" /XP"+", "+Chr(34)+Chr(34)+", 1)")
RunProgram(PBCompiler$, Path$+"SetupMain.pb /EXE "+Chr(34)+Path$+"Setup.exe"+Chr(34)+" /ICON "+Chr(34)+Path$+"Setup.ico"+Chr(34)+" /XP", "", 1)
PrintN("RunProgram("+Chr(34)+PBCompiler$+Chr(34)+", "+Chr(34)+Path$+"SetupMain.pb /EXE "+Path$+"Setup.exe /ICON "+Path$+"Setup.ico"+Chr(34)+" /XP"+", "+Chr(34)+Chr(34)+", 1)")
PrintN("Compil"+Chr(130))
PrintN("--- Termin"+Chr(130)+" ---")
PrintN("Appuyez sur une touche pour continuer...")
Repeat
Delay(1)
Until Inkey()

Je vais encore améliorer le tout, et je mettrais à jour
