Code cleaning
This commit is contained in:
@@ -1060,13 +1060,15 @@ Procedure.s str2curl(string.s)
|
|||||||
ProcedureReturn ""
|
ProcedureReturn ""
|
||||||
EndIf
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
|
||||||
; IDE Options = PureBasic 5.40 LTS Beta 5 (Windows - x86)
|
; IDE Options = PureBasic 5.40 LTS Beta 5 (Windows - x86)
|
||||||
; EnableUnicode
|
; EnableUnicode
|
||||||
; EnableXP
|
; EnableXP
|
||||||
; EnableBuildCount = 0
|
; EnableBuildCount = 0
|
||||||
; IDE Options = PureBasic 5.42 LTS (Windows - x86)
|
; IDE Options = PureBasic 5.42 LTS (Windows - x86)
|
||||||
; CursorPosition = 1048
|
; CursorPosition = 1031
|
||||||
; FirstLine = 1008
|
; FirstLine = 986
|
||||||
; Folding = --
|
; Folding = --
|
||||||
; EnableUnicode
|
; EnableUnicode
|
||||||
; EnableXP
|
; EnableXP
|
143
osm.pb
143
osm.pb
@@ -125,7 +125,6 @@ Module OSM
|
|||||||
|
|
||||||
Moving.i
|
Moving.i
|
||||||
Dirty.i ;To signal that drawing need a refresh
|
Dirty.i ;To signal that drawing need a refresh
|
||||||
;CurlMutex.i ;CurlMutex.i ;seems that I can't thread curl ! :(((((
|
|
||||||
|
|
||||||
MainDrawingThread.i
|
MainDrawingThread.i
|
||||||
List TilesThreads.TileThread()
|
List TilesThreads.TileThread()
|
||||||
@@ -143,107 +142,7 @@ Module OSM
|
|||||||
|
|
||||||
;- *** CURL specific ***
|
;- *** CURL specific ***
|
||||||
|
|
||||||
; Global *ReceiveHTTPToMemoryBuffer, ReceiveHTTPToMemoryBufferPtr.i, ReceivedData.s
|
|
||||||
IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl
|
IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl
|
||||||
;
|
|
||||||
; ProcedureC ReceiveHTTPWriteToMemoryFunction(*ptr, Size.i, NMemB.i, *Stream)
|
|
||||||
;
|
|
||||||
; Protected SizeProper.i = Size & 255
|
|
||||||
; Protected NMemBProper.i = NMemB
|
|
||||||
;
|
|
||||||
; If *ReceiveHTTPToMemoryBuffer = 0
|
|
||||||
; *ReceiveHTTPToMemoryBuffer = AllocateMemory(SizeProper * NMemBProper)
|
|
||||||
; If *ReceiveHTTPToMemoryBuffer = 0
|
|
||||||
; Debug "Problem allocating memory"
|
|
||||||
; End
|
|
||||||
; EndIf
|
|
||||||
; Else
|
|
||||||
; *ReceiveHTTPToMemoryBuffer = ReAllocateMemory(*ReceiveHTTPToMemoryBuffer, MemorySize(*ReceiveHTTPToMemoryBuffer) + SizeProper * NMemBProper)
|
|
||||||
; If *ReceiveHTTPToMemoryBuffer = 0
|
|
||||||
; Debug "Problem reallocating memory"
|
|
||||||
; End
|
|
||||||
; EndIf
|
|
||||||
; EndIf
|
|
||||||
;
|
|
||||||
; CopyMemory(*ptr, *ReceiveHTTPToMemoryBuffer + ReceiveHTTPToMemoryBufferPtr, SizeProper * NMemBProper)
|
|
||||||
; ReceiveHTTPToMemoryBufferPtr + SizeProper * NMemBProper
|
|
||||||
;
|
|
||||||
; ProcedureReturn SizeProper * NMemBProper
|
|
||||||
;
|
|
||||||
; EndProcedure
|
|
||||||
;
|
|
||||||
; Procedure.i CurlReceiveHTTPToMemory(URL$, ProxyURL$="", ProxyPort$="", ProxyUser$="", ProxyPassword$="")
|
|
||||||
;
|
|
||||||
; Protected *Buffer, curl.i, Timeout.i, res.i
|
|
||||||
;
|
|
||||||
; ;Debug "ReceiveHTTPToMemory" + URL$ + ProxyURL$ + ProxyPort$ + ProxyUser$ + ProxyPassword$
|
|
||||||
;
|
|
||||||
; If Len(URL$)
|
|
||||||
;
|
|
||||||
; curl = curl_easy_init()
|
|
||||||
;
|
|
||||||
; If curl
|
|
||||||
;
|
|
||||||
; Timeout = 3
|
|
||||||
;
|
|
||||||
; curl_easy_setopt(curl, #CURLOPT_URL, str2curl(URL$))
|
|
||||||
; curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, 0)
|
|
||||||
; curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, 0)
|
|
||||||
; curl_easy_setopt(curl, #CURLOPT_HEADER, 0)
|
|
||||||
; curl_easy_setopt(curl, #CURLOPT_FOLLOWLOCATION, 1)
|
|
||||||
; curl_easy_setopt(curl, #CURLOPT_TIMEOUT, Timeout)
|
|
||||||
;
|
|
||||||
; If Len(ProxyURL$)
|
|
||||||
; ;curl_easy_setopt(curl, #CURLOPT_HTTPPROXYTUNNEL, #True)
|
|
||||||
; If Len(ProxyPort$)
|
|
||||||
; ProxyURL$ + ":" + ProxyPort$
|
|
||||||
; EndIf
|
|
||||||
; ; Debug ProxyURL$
|
|
||||||
; curl_easy_setopt(curl, #CURLOPT_PROXY, str2curl(ProxyURL$))
|
|
||||||
; If Len(ProxyUser$)
|
|
||||||
; If Len(ProxyPassword$)
|
|
||||||
; ProxyUser$ + ":" + ProxyPassword$
|
|
||||||
; EndIf
|
|
||||||
; ;Debug ProxyUser$
|
|
||||||
; curl_easy_setopt(curl, #CURLOPT_PROXYUSERPWD, str2curl(ProxyUser$))
|
|
||||||
; EndIf
|
|
||||||
; EndIf
|
|
||||||
;
|
|
||||||
; ;TODO improve with https://github.com/Progi1984/RWrappers/tree/master/LibCurl
|
|
||||||
; curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToMemoryFunction())
|
|
||||||
; LockMutex(OSM\CurlMutex)
|
|
||||||
; res = curl_easy_perform(curl)
|
|
||||||
; UnlockMutex(OSM\CurlMutex)
|
|
||||||
;
|
|
||||||
; If res = #CURLE_OK
|
|
||||||
;
|
|
||||||
; *Buffer = AllocateMemory(ReceiveHTTPToMemoryBufferPtr)
|
|
||||||
; If *Buffer
|
|
||||||
; CopyMemory(*ReceiveHTTPToMemoryBuffer, *Buffer, ReceiveHTTPToMemoryBufferPtr)
|
|
||||||
; FreeMemory(*ReceiveHTTPToMemoryBuffer)
|
|
||||||
; *ReceiveHTTPToMemoryBuffer = #Null
|
|
||||||
; ReceiveHTTPToMemoryBufferPtr = 0
|
|
||||||
; Else
|
|
||||||
; ; Debug "Problem allocating buffer"
|
|
||||||
; EndIf
|
|
||||||
; ;curl_easy_cleanup(curl) ;Was its original place but moved below as it seems more logical to me.
|
|
||||||
; Else
|
|
||||||
; ; Debug "CURL NOT OK"
|
|
||||||
; EndIf
|
|
||||||
;
|
|
||||||
; curl_easy_cleanup(curl)
|
|
||||||
;
|
|
||||||
; Else
|
|
||||||
; ; Debug "Can't Init CURL"
|
|
||||||
; EndIf
|
|
||||||
;
|
|
||||||
; EndIf
|
|
||||||
;
|
|
||||||
; ; Debug "Curl Buffer : " + Str(*Buffer)
|
|
||||||
;
|
|
||||||
; ProcedureReturn *Buffer
|
|
||||||
;
|
|
||||||
; EndProcedure
|
|
||||||
|
|
||||||
ProcedureC ReceiveHTTPWriteToFileFunction(*ptr, Size.i, NMemB.i, FileHandle.i)
|
ProcedureC ReceiveHTTPWriteToFileFunction(*ptr, Size.i, NMemB.i, FileHandle.i)
|
||||||
|
|
||||||
@@ -256,8 +155,8 @@ Module OSM
|
|||||||
Protected *Buffer, curl.i, Timeout.i, res.i
|
Protected *Buffer, curl.i, Timeout.i, res.i
|
||||||
Protected FileHandle.i
|
Protected FileHandle.i
|
||||||
|
|
||||||
Debug "ReceiveHTTPToFile from " + URL$ + " " + ProxyURL$ + ProxyPort$ + ProxyUser$
|
;Debug "ReceiveHTTPToFile from " + URL$ + " " + ProxyURL$ + ProxyPort$ + ProxyUser$
|
||||||
Debug " to file : " + DestFileName$
|
;Debug " to file : " + DestFileName$
|
||||||
|
|
||||||
FileHandle = CreateFile(#PB_Any, DestFileName$)
|
FileHandle = CreateFile(#PB_Any, DestFileName$)
|
||||||
|
|
||||||
@@ -296,9 +195,9 @@ Module OSM
|
|||||||
|
|
||||||
curl_easy_setopt(curl, #CURLOPT_WRITEDATA, FileHandle)
|
curl_easy_setopt(curl, #CURLOPT_WRITEDATA, FileHandle)
|
||||||
curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToFileFunction())
|
curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @ReceiveHTTPWriteToFileFunction())
|
||||||
;LockMutex(OSM\CurlMutex) ;Not any more necessary
|
|
||||||
res = curl_easy_perform(curl)
|
res = curl_easy_perform(curl)
|
||||||
;UnlockMutex(OSM\CurlMutex)
|
|
||||||
If res <> #CURLE_OK
|
If res <> #CURLE_OK
|
||||||
Debug "CURL NOT OK"
|
Debug "CURL NOT OK"
|
||||||
EndIf
|
EndIf
|
||||||
@@ -330,7 +229,6 @@ Module OSM
|
|||||||
OSM\ZoomMax = 18
|
OSM\ZoomMax = 18
|
||||||
OSM\MoveStartingPoint\x = - 1
|
OSM\MoveStartingPoint\x = - 1
|
||||||
OSM\TileSize = 256
|
OSM\TileSize = 256
|
||||||
;OSM\CurlMutex = CreateMutex()
|
|
||||||
OSM\Dirty = #False
|
OSM\Dirty = #False
|
||||||
OSM\Drawing\Mutex = CreateMutex()
|
OSM\Drawing\Mutex = CreateMutex()
|
||||||
OSM\Drawing\Semaphore = CreateSemaphore()
|
OSM\Drawing\Semaphore = CreateSemaphore()
|
||||||
@@ -528,24 +426,16 @@ Module OSM
|
|||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.i GetTileFromHDD(CacheFile.s)
|
Procedure.i GetTileFromHDD(CacheFile.s)
|
||||||
|
Protected nImage.i
|
||||||
Protected nImage.i
|
|
||||||
|
|
||||||
If FileSize(CacheFile) > 0
|
If FileSize(CacheFile) > 0
|
||||||
|
|
||||||
nImage = LoadImage(#PB_Any, CacheFile)
|
nImage = LoadImage(#PB_Any, CacheFile)
|
||||||
|
|
||||||
If IsImage(nImage)
|
If IsImage(nImage)
|
||||||
Debug "Loadimage " + CacheFile + " -> Success !"
|
;Debug "Loadimage " + CacheFile + " -> Success !"
|
||||||
ProcedureReturn nImage
|
ProcedureReturn nImage
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
EndIf
|
EndIf
|
||||||
|
;Debug "Loadimage " + CacheFile + " -> Failed !"
|
||||||
Debug "Loadimage " + CacheFile + " -> Failed !"
|
|
||||||
|
|
||||||
ProcedureReturn -1
|
ProcedureReturn -1
|
||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.i GetTileFromWeb(Zoom.i, XTile.i, YTile.i, CacheFile.s)
|
Procedure.i GetTileFromWeb(Zoom.i, XTile.i, YTile.i, CacheFile.s)
|
||||||
@@ -554,18 +444,15 @@ Module OSM
|
|||||||
Protected nImage.i = -1
|
Protected nImage.i = -1
|
||||||
Protected FileHandle.i
|
Protected FileHandle.i
|
||||||
|
|
||||||
Protected TileURL.s = OSM\ServerURL + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png"
|
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
|
If Proxy
|
||||||
;*Buffer = CurlReceiveHTTPToMemory(TileURL, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$)
|
|
||||||
FileHandle = CurlReceiveHTTPToFile(TileURL, CacheFile, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$)
|
FileHandle = CurlReceiveHTTPToFile(TileURL, CacheFile, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$)
|
||||||
If FileHandle
|
If FileHandle
|
||||||
nImage = GetTileFromHDD(CacheFile)
|
nImage = GetTileFromHDD(CacheFile)
|
||||||
Else
|
Else
|
||||||
Debug "File " + TileURL + " not correctly received with Curl and proxy"
|
;Debug "File " + TileURL + " not correctly received with Curl and proxy"
|
||||||
EndIf
|
EndIf
|
||||||
Else
|
Else
|
||||||
*Buffer = ReceiveHTTPMemory(TileURL) ;TODO to thread by using #PB_HTTP_Asynchronous
|
*Buffer = ReceiveHTTPMemory(TileURL) ;TODO to thread by using #PB_HTTP_Asynchronous
|
||||||
@@ -573,16 +460,16 @@ Module OSM
|
|||||||
If *Buffer
|
If *Buffer
|
||||||
nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer))
|
nImage = CatchImage(#PB_Any, *Buffer, MemorySize(*Buffer))
|
||||||
If IsImage(nImage)
|
If IsImage(nImage)
|
||||||
Debug "Load from web " + TileURL + " as Tile nb " + nImage
|
;Debug "Load from web " + TileURL + " as Tile nb " + nImage
|
||||||
SaveImage(nImage, CacheFile, #PB_ImagePlugin_PNG)
|
SaveImage(nImage, CacheFile, #PB_ImagePlugin_PNG)
|
||||||
FreeMemory(*Buffer)
|
FreeMemory(*Buffer)
|
||||||
Else
|
Else
|
||||||
Debug "Can't catch image " + TileURL
|
;Debug "Can't catch image " + TileURL
|
||||||
nImage = -1
|
nImage = -1
|
||||||
;ShowMemoryViewer(*Buffer, MemorySize(*Buffer))
|
;ShowMemoryViewer(*Buffer, MemorySize(*Buffer))
|
||||||
EndIf
|
EndIf
|
||||||
Else
|
Else
|
||||||
Debug "ReceiveHTTPMemory's buffer is empty"
|
;Debug "ReceiveHTTPMemory's buffer is empty"
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
@@ -1170,8 +1057,8 @@ CompilerEndIf
|
|||||||
|
|
||||||
; IDE Options = PureBasic 5.42 LTS (Windows - x86)
|
; IDE Options = PureBasic 5.42 LTS (Windows - x86)
|
||||||
; ExecutableFormat = Console
|
; ExecutableFormat = Console
|
||||||
; CursorPosition = 146
|
; CursorPosition = 435
|
||||||
; FirstLine = 117
|
; FirstLine = 448
|
||||||
; Folding = -------
|
; Folding = -------
|
||||||
; EnableUnicode
|
; EnableUnicode
|
||||||
; EnableThread
|
; EnableThread
|
||||||
|
Reference in New Issue
Block a user