From 38f82378c2fa636c028bc5875cd1286e0031b233 Mon Sep 17 00:00:00 2001 From: djes Date: Mon, 1 Aug 2016 16:25:58 +0200 Subject: [PATCH] curl fix --- libcurl.pbi | 17 +++++++++++------ osm.pb | 27 ++++++++++++++------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/libcurl.pbi b/libcurl.pbi index 857542a..3c58846 100644 --- a/libcurl.pbi +++ b/libcurl.pbi @@ -1049,19 +1049,24 @@ Procedure.s curlGetData() EndProcedure Procedure.s str2curl(string.s) - Protected *curlstring - If *curlstring : FreeMemory(*curlstring) : EndIf + Protected *curlstring, newstring.s *curlstring = AllocateMemory(Len(string) + 1) - PokeS(*curlstring,string,-1,#PB_Ascii) - ProcedureReturn PeekS(*curlstring,-1) + If *curlstring + PokeS(*curlstring,string,-1,#PB_Ascii) + newstring = PeekS(*curlstring,-1) + FreeMemory(*curlstring) + ProcedureReturn newstring + Else + ProcedureReturn "" + EndIf EndProcedure ; IDE Options = PureBasic 5.40 LTS Beta 5 (Windows - x86) ; EnableUnicode ; EnableXP ; EnableBuildCount = 0 ; IDE Options = PureBasic 5.42 LTS (Windows - x86) -; CursorPosition = 1041 -; FirstLine = 1003 +; CursorPosition = 1057 +; FirstLine = 1008 ; Folding = -- ; EnableUnicode ; EnableXP \ No newline at end of file diff --git a/osm.pb b/osm.pb index a635ef2..7c8862e 100644 --- a/osm.pb +++ b/osm.pb @@ -122,7 +122,8 @@ Module OSM Moving.i Dirty.i ;To signal that drawing need a refresh - ;CurlMutex.i ;seems that I can't thread curl ! :((((( + CurlMutex.i ;CurlMutex.i ;seems that I can't thread curl ! :((((( + List TilesThreads.TileThread() List track.Location() ;to display a GPX track @@ -242,7 +243,7 @@ Module OSM OSM\ZoomMax = 18 OSM\MoveStartingPoint\x = - 1 OSM\TileSize = 256 - ;OSM\CurlMutex = CreateMutex() + OSM\CurlMutex = CreateMutex() OSM\Dirty = #False OSM\Drawing\Mutex = CreateMutex() OSM\Drawing\Semaphore = CreateSemaphore() @@ -250,7 +251,7 @@ Module OSM OSM\Font=LoadFont(#PB_Any, "Comic Sans MS", 20, #PB_Font_Bold) ;- Proxy details - Global Proxy = #False + Global Proxy = #True ;Use this to customize your preferences ; Result = CreatePreferences(GetHomeDirectory() + "OSM.prefs") @@ -448,30 +449,30 @@ Module OSM Protected TileURL.s = OSM\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png" Protected CacheFile.s = "OSM_" + Str(Zoom) + "_" + Str(XTile) + "_" + Str(YTile) + ".png" - ; Debug "Check if we have this image on Web" + Debug "Check if we have this image on Web" If Proxy - ;LockMutex(OSM\CurlMutex) ;Seems no more necessary + LockMutex(OSM\CurlMutex) ;Seems no more necessary *Buffer = CurlReceiveHTTPToMemory(TileURL, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$) - ;UnlockMutex(OSM\CurlMutex) + UnlockMutex(OSM\CurlMutex) Else *Buffer = ReceiveHTTPMemory(TileURL) ;TODO to thread by using #PB_HTTP_Asynchronous EndIf - ; Debug "Image buffer " + Str(*Buffer) + Debug "Image buffer " + Str(*Buffer) If *Buffer nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer)) If IsImage(nImage) - ; Debug "Load from web " + TileURL + " as Tile nb " + nImage + Debug "Load from web " + TileURL + " as Tile nb " + nImage SaveImage(nImage, OSM\HDDCachePath + CacheFile, #PB_ImagePlugin_PNG) FreeMemory(*Buffer) Else - ; Debug "Can't catch image " + TileURL + Debug "Can't catch image " + TileURL nImage = -1 ;ShowMemoryViewer(*Buffer, MemorySize(*Buffer)) EndIf Else - ; Debug "Problem loading from web " + TileURL + Debug "Problem loading from web " + TileURL EndIf ProcedureReturn nImage @@ -1053,9 +1054,9 @@ CompilerIf #PB_Compiler_IsMainFile EndIf CompilerEndIf -; IDE Options = PureBasic 5.42 LTS (Windows - x64) -; CursorPosition = 883 -; FirstLine = 869 +; IDE Options = PureBasic 5.42 LTS (Windows - x86) +; CursorPosition = 245 +; FirstLine = 235 ; Folding = ------- ; EnableUnicode ; EnableThread