Seite 3 von 5

Verfasst: 22.01.2009 11:04
von HeX0R
Ich hab das nun geändert, es blinkt nun rot, das sollte hoffentlich eindeutiger sein.

Einfach zip nochmal laden.

Was sind schon 3 Stunden... :mrgreen:

Verfasst: 22.01.2009 11:40
von HeX0R
Ein kleines Update der Include:

Man sollte erst die heruntergeladene Datei schliessen, und dann die Message abschicken. (D'OH)

Verfasst: 23.01.2009 15:35
von ts-soft
Hab den Updater hier mal eingebaut.
Funktioniert sehr gut :allright:

Verfasst: 02.02.2009 16:25
von HeX0R
Nochmal ein Miniupdate:

Der Proxy hier im Geschäft, wollte die Dateien immerwieder aus seinem Cache laden (den er erst alle Stunde erneuert).
Also habe ich noch das Flag INTERNET_FLAG_PRAGMA_NOCACHE hinzugefügt (Zeile 113/114).

Verfasst: 27.02.2009 11:07
von HeX0R
Hier ein "Little Helper", um das Einbauen ins eigene Programm möglichst einfach zu gestalten:
[Edit]
Little Helper entfernt, die Callback-Methode ist vorzuziehen!

Verfasst: 27.02.2009 11:35
von Little John
Hallo,

schonmal vielen Dank im Voraus. ;-) Ist nur eine Frage der Zeit, bis ich das gebrauchen kann. :allright:

Gruß, Little John

Verfasst: 27.02.2009 23:54
von HeX0R
Auf vielfachen Wunsch eines Einzelnen, wurde noch eine (optionale) Authorisierung eingebaut.

Ausserdem habe ich im Little Helper versehentlich ein WindowEvent() anstatt EventWindow() benutzt, was zu etwas seltsamen Vorkommnissen führen kann...

Hier ein Beispiel, einer via Username/Passwort gesicherten Seite:

Code: Alles auswählen

;/-------------
;| Example for the
;| CheckForUpdates.pbi
;|
;| Should be easy to understand
;| and also easy to integrate
;| in own applications.
;|
;| PB >= 4.0 (no DEMO)
;|
;| ©HeX0R 2009
;|
;| UPDATE !!21.05.2009!!
;| Now with auto url-detection
;| in Update-Description
;|
;| UPDATE !!17.09.2009!!
;| Updatewindow has its own
;| Callback
;|
;/-------------

XIncludeFile "..\CheckForUpdates.pbi"

InitNetwork()

#URL_OF_INFOFILE = "http://h3x0r.ath.cx/hidden/example.dat"

;Our VersionInfo Variable
;-Integrate (Add Global variable)
Global VI._CFU_VERSION_INFO_

;-Integrate (Add new Events)
Enumeration #WM_APP + 2
	#EVENT_VERSION_INFO_RECEIVED
	#EVENT_DOWNLOAD_FINISHED
EndEnumeration

Enumeration
	#Window_Main
	;
	;-Integrate (Add Window Constant)
	;If you want to use the OpenWindow_NewUpdate-Procedure in your own prog
	;you have to integrate the following Windowconstant into your main window enumeration:
	#Window_NewUpdate
EndEnumeration

Enumeration
	#Button_Start_Check
	#Editor_0
	;
	;-Integrate (Add Gadget Constants)
	;If you want to use the OpenWindow_NewUpdate-Procedure in your own prog
	;you have to integrate the following Gadgetconstants into your main gadget enumeration:
	#Button_Update_Load
	#Button_Update_Link
	#Button_Update_Close
	#Editor_Update_Description
	#ProgressBar_Update
EndEnumeration

;-Integrate following two Procedures
Procedure.s ByteRechner(dSize.d)
	Protected Namen = $4B4D4754, i = 24, C.c, Result.s = "0"

	If dSize > 0.0
		While dSize > 1024 And i >= 0
			dSize / 1024
			C = (Namen >> i) & $FF
			i - 8
		Wend
		Result = StrD(dSize, 2) + " " + Chr(C) + "Byte"
	EndIf
	ProcedureReturn Result
EndProcedure

Procedure NewUpdateWindow_CallBack(Window, Msg, wparam, lparam)
	Protected StringBuffer.s, *el.ENLINK, txt.TEXTRANGE, w, h

	Select Msg
		Case #WM_NOTIFY
			*el = lParam
			If *el\nmhdr\idFrom = #Editor_Update_Description
				If *el\nmhdr\code = #EN_LINK
					If *el\msg = #WM_LBUTTONDOWN
						StringBuffer   = Space(1024)
						txt\chrg\cpMin = *el\chrg\cpMin
						txt\chrg\cpMax = *el\chrg\cpMax
						txt\lpstrText  = @StringBuffer
						SendMessage_(*el\nmhdr\hwndFrom, #EM_GETTEXTRANGE, 0, txt)
						If StringBuffer
							If Left(LCase(StringBuffer), 3) = "www"
								StringBuffer = "http://" + StringBuffer
							EndIf
							RunProgram(StringBuffer)
						EndIf
					EndIf
				EndIf
			EndIf
		
	EndSelect
	
	ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

;/ New Update found Window Example
Procedure OpenWindow_NewUpdate(Parent = 0)
	Protected i

	OpenWindow(#Window_NewUpdate, 0, 0, 300, 350, "New update found!", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_WindowCentered, Parent)
	CompilerIf #PB_Compiler_Version < 430
	CreateGadgetList(WindowID(#Window_NewUpdate))
	CompilerEndIf
	SetWindowCallback(@NewUpdateWindow_CallBack(), #Window_NewUpdate)
	TextGadget(#PB_Any, 5, 5, 100, 20, "Name:")
	StringGadget(#PB_Any, 105, 3, 190, 22, VI\Name, #PB_String_ReadOnly)
	TextGadget(#PB_Any, 5, 30, 100, 20, "Version:")
	StringGadget(#PB_Any, 105, 28, 190, 22, VI\Version, #PB_String_ReadOnly)
	TextGadget(#PB_Any, 5, 55, 100, 20, "ReleaseDate:")
	StringGadget(#PB_Any, 105, 53, 190, 22, FormatDate("%dd.%mm.%yyyy %hh:%ii", VI\ReleaseDate), #PB_String_ReadOnly)
	TextGadget(#PB_Any, 5, 80, 100, 20, "FileSize:")
	StringGadget(#PB_Any, 105, 78, 190, 22, ByteRechner(VI\FileSize), #PB_String_ReadOnly)
	TextGadget(#PB_Any, 5, 105, 100, 20, "Info:")
	EditorGadget(#Editor_Update_Description, 5, 130, 290, 165, #PB_Editor_ReadOnly)
	ButtonGadget(#Button_Update_Load, 5, 300, 70, 22, "Download", #PB_Button_Default)
	If Left(LCase(VI\InfoLink), 7) = "http://"
		ButtonGadget(#Button_Update_Link, 115, 300, 70, 22, "Info")
	EndIf
	ButtonGadget(#Button_Update_Close, 225, 300, 70, 22, "Close")
	ProgressBarGadget(#ProgressBar_Update, 5, 325, 290, 20, 0, 100)

	;Activate WordWrap in EditorGadget
	SendMessage_(GadgetID(#Editor_Update_Description), #EM_SETTARGETDEVICE, 0, 0)
	;Enable Auto URL-Detection
	i = SendMessage_(GadgetID(#Editor_Update_Description), #EM_GETEVENTMASK, 0, 0)
	SendMessage_(GadgetID(#Editor_Update_Description), #EM_SETEVENTMASK, 0, i | #ENM_LINK)
	SendMessage_(GadgetID(#Editor_Update_Description), #EM_AUTOURLDETECT, #True, 0)
	;Check, if there is any Description
	If VI\Description
		CFU_Editor_Load(#Editor_Update_Description, VI\Description)
		FreeMemory(VI\Description)
	EndIf
EndProcedure

Procedure MyCallBack(Window, Msg, wparam, lparam)
	Protected Result = #PB_ProcessPureBasicEvents, StringBuffer.s, *el.ENLINK, txt.TEXTRANGE

	;Here are our two new Window-events
	;those Messages get sent through PostMessage, so you will see
	;them also in your mainloop.
	;But i decided to do it inside the callback because of two reasons:
	;
	; 1.) EventwParam() will be obsolete and removed someday (maybe)
	; 2.) There is a bug, when user moves the window:
	;     http://www.purebasic.fr/english/viewtopic.php?t=36027
	;     So it is possible, that messages never will arrive

	Select Msg
		;-Integrate (Callback)

		Case #EVENT_VERSION_INFO_RECEIVED
			If CFU_CheckVersionInfo(@VI, wParam)
				;Ok, we have some info!
				;Now we should check if MV\Version is newer then our Version
				;But as long as this is just an example, we go on and show the window

				OpenWindow_NewUpdate(WindowID(#Window_Main))
			EndIf

		Case #EVENT_DOWNLOAD_FINISHED
			If wParam
				AddGadgetItem(#Editor_0, -1, "Download finished!, File should be here:")
				AddGadgetItem(#Editor_0, -1, GetTemporaryDirectory() + VI\ServerFileName)
				;Check integrity of downloaded file
				If MD5FileFingerprint(GetTemporaryDirectory() + VI\ServerFileName) = VI\MD5
					;Now run Patch (well, this time, this is no patch)
					RunProgram(GetTemporaryDirectory() + VI\ServerFileName)
					;Send close message to own Program
					SendMessage_(WindowID(#Window_Main), #WM_CLOSE, #Null, #Null)
				Else
					AddGadgetItem(#Editor_0, -1, "File seems to be corrupted!")
				EndIf
			Else
				AddGadgetItem(#Editor_0, -1, "Something went wrong with the download!")
			EndIf
			DisableGadget(#Button_Update_Load, 0)

	EndSelect

	ProcedureReturn Result
EndProcedure

Procedure main()

	OpenWindow(#Window_Main, 0, 0, 400, 400, "VersionCheck-Test", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
	CompilerIf #PB_Compiler_Version < 430
	CreateGadgetList(WindowID(#Window_Main))
	CompilerEndIf
	SetWindowCallback(@MyCallBack(), #Window_Main)
	ButtonGadget(#Button_Start_Check, 140, 5, 120, 22, "Start Check Now")
	EditorGadget(#Editor_0, 5, 35, 390, 360)

	;Main Loop
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_CloseWindow

				Select EventWindow()
					Case #Window_Main
						Break
						;-Integrate (CloseWindow)
					Case #Window_NewUpdate
						CloseWindow(#Window_NewUpdate)
				EndSelect

			Case #PB_Event_Gadget

				Select EventGadget()
					Case #Button_Start_Check
						;Start the Check-Thread
						CFU_LoadVersionInfo(#URL_OF_INFOFILE, WindowID(#Window_Main), #EVENT_VERSION_INFO_RECEIVED, "affen", "kopf", #CFU_VERSIONINFO_AUTH)
						;We will get informed through a #EVENT_VERSION_INFO_RECEIVED Event, when info download is finished

						;-Integrate (EventGadget)
						;Integrate those three buttons into your main eventloop:
					Case #Button_Update_Link
						RunProgram(VI\InfoLink)
					Case #Button_Update_Close
						CloseWindow(#Window_NewUpdate)
					Case #Button_Update_Load
						;Start the download
						If CFU_LoadInternetFile(VI\URL, GetTemporaryDirectory() + VI\ServerFileName, WindowID(#Window_Main), #EVENT_DOWNLOAD_FINISHED, VI\FileSize, #ProgressBar_Update)
							;We will get informed through a #EVENT_DOWNLOAD_FINISHED Event, when file download is finished
							DisableGadget(#Button_Update_Load, 1)
						EndIf
				EndSelect

		EndSelect

	ForEver

EndProcedure

main()
End

Verfasst: 17.05.2009 12:31
von ts-soft
Alle geht, aber es kommt nur eine 0 Byte Datei an, wParam bleibt 0 :(

Was ist da los?

Verfasst: 17.05.2009 21:02
von HeX0R
Vermutlich stimmt der Downloadlink to file nicht?

Wenn du das dort eingetragene in die Browser-Adressleiste kopierst, kommt das File dann angeflogen?

Verfasst: 17.05.2009 21:14
von ts-soft
Das war das einzig leere Feld :mrgreen:

Nach Eintragen und mehrmaligen weiteren Tests, gings dann irgendwann.
Seither läuft es :D

Ich sollte mal öfter schlafen gehen :mrgreen:

Gruß und dank

Thomas

PS: Die neue Kurzversion geht garnicht, wenn man ein eigenes WinCB hat.
Da passiert überhaupt nischt. Sollteste vielleicht mal drauf hinweisen.