{"id":23,"date":"2014-06-16T04:10:00","date_gmt":"2014-06-16T08:10:00","guid":{"rendered":"http:\/\/naplandgames.com\/blog\/2014\/06\/16\/agk-tutorial-app-data\/"},"modified":"2018-12-18T09:13:58","modified_gmt":"2018-12-18T14:13:58","slug":"agk-tutorial-app-data","status":"publish","type":"post","link":"https:\/\/naplandgames.com\/blog\/2014\/06\/16\/agk-tutorial-app-data\/","title":{"rendered":"AGK Tutorial &#8211; App Data"},"content":{"rendered":"<div style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21.600000381469727px; text-align: center;\">Originally published in the <a href=\"http:\/\/www.thegamecreators.com\/pages\/newsletters\/newsletter_issue_136.html\" target=\"_blank\" rel=\"noopener\">TGC Newsletter &#8211; June 1, 2014<\/a><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/naplandgames.com\/blog\/wp-content\/uploads\/2018\/12\/80d1107e1d6bedd230764ba7f82373d2.jpg\" alt=\"\" width=\"700\" height=\"120\" \/><\/p>\n<div style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21.600000381469727px;\"><span style=\"line-height: 1.5;\">The question of transferring data from your mobile app to a server was brought up by Parry on the AGK forums and I thought I&#8217;d share my process for getting app data from a device. The problem is that Android and iOS put app data in a protected folder on the device. If you want to root or\u00a0<\/span><a style=\"color: #996699;\" href=\"http:\/\/en.wikipedia.org\/wiki\/Jailbreak_(computer_science)#Jailbreaking\" target=\"_blank\" rel=\"noopener\">jailbreak\u00a0<\/a><span style=\"line-height: 1.5;\">the device it is easy to get at, but this process can be dangerous and complex. If you just need a peek at your app&#8217;s data then there is an easier way: add all of the files to a ZIP file and send it to a server.<\/span><\/div>\n<div style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21.600000381469727px;\"><\/div>\n<h4 style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21.600000381469727px;\">Setup<\/h4>\n<div style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21.600000381469727px;\"><span style=\"line-height: 1.5;\">To start you&#8217;ll need a server. You can use your hosted account or a server of your own. If you&#8217;re on Windows I highly suggest using\u00a0<\/span><a style=\"color: #996699;\" href=\"http:\/\/www.apachefriends.org\/\" target=\"_blank\" rel=\"noopener\">XAMPP<\/a><span style=\"line-height: 1.5;\">. The setup is quick and they provide ample information on how to get things going (like allowing outside connections to your server). The next thing you&#8217;ll want to do is set up some PHP code on the server to accept files as well as the code in AGK to send the files.\u00a0<\/span><\/div>\n<div style=\"font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21.600000381469727px;\">\n<div><\/div>\n<div>AGK code for sending file:<\/div>\n<div><\/div>\n<pre style=\"background: #eeecf6; border: 1px solid #cccccc; color: #493617; padding-left: 16px;\">fileID = OpenToWrite(\"test.txt\" , 0)\r\nWriteLine(fileID , \"this is a test\")\r\nCloseFile(fileID)\r\ncid = CreateHTTPConnection()\r\nSetHTTPHost(cid, \"1.1.1.1\" , 0)\u00a0\r\nSendHTTPFile(cid , \"uploadfile.php\" , \"\" , \"test.txt\")\r\nSetPrintSize(1)\r\nrepeat\r\n\u00a0 \u00a0 if GetHTTPResponseReady( cid ) = 1\r\n\u00a0 \u00a0 \u00a0 \u00a0 print (GetHTTPResponse( cid ))\r\n\u00a0 \u00a0 else\r\n\u00a0 \u00a0 \u00a0 \u00a0 print ( GetHTTPFileProgress( cid ))\r\n\u00a0 \u00a0 endif\r\n\u00a0 \u00a0 Sync()\r\nuntil done = 1\r\nCloseHTTPConnection(cid)\r\nDeleteHTTPConnection(cid)\r\nEND<\/pre>\n<div>\n<p>Ensure that the IP Address 1.1.1.1 is replaced with your own IP address or domain (do not include HTTP:\/\/).<\/p>\n<\/div>\n<div><\/div>\n<div>PHP code for receiving file:<\/div>\n<div><\/div>\n<pre style=\"background: #eeecf6; border: 1px solid #cccccc; color: #493617; padding-left: 16px;\">&lt;?PHP\r\nif ($_FILES[\"myfile\"][\"error\"] &gt; 0){\r\n\u00a0 \u00a0 \u00a0 \u00a0 echo \"Error: \" . $_FILES[\"myfile\"][\"error\"] . \"n\";\r\n}\r\nelse {\r\n\u00a0 \u00a0 echo \"Upload: \" . $_FILES[\"myfile\"][\"name\"] . \"n\";\r\n\u00a0 \u00a0 echo \"Type: \" . $_FILES[\"myfile\"][\"type\"] . \"n\";\r\n\u00a0 \u00a0 echo \"Size: \" . ($_FILES[\"myfile\"][\"size\"] \/ 1024) . \" Kbn\";\r\n\u00a0 \u00a0 echo \"Stored in: \" . $_FILES[\"myfile\"][\"tmp_name\"] . \" n\";  \r\n  \u00a0 if (file_exists(\"upload\/\" . $_FILES[\"myfile\"][\"name\"]))\r\n\u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 echo $_FILES[\"myfile\"][\"name\"] . \" already exists. nn\";\r\n\u00a0 \u00a0 }\r\n\u00a0 \u00a0 else\r\n\u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 move_uploaded_file($_FILES[\"myfile\"][\"tmp_name\"], \"upload\/\" . $_FILES[\"myfile\"][\"name\"]);\r\n\u00a0 \u00a0 \u00a0 \u00a0 echo \"Stored in: \" . \"upload\/\" . $_FILES[\"myfile\"][\"name\"] . \" nn\";\r\n\u00a0 \u00a0 }\r\n}\r\n?&gt;<\/pre>\n<div><\/div>\n<div>It&#8217;s as simple as that. Just make sure that the &#8220;upload&#8221; directory is created on your server before trying to send the file. Now that you have all of that set up and tested we&#8217;re on to a simple set of code that will get all of the files out of your app&#8217;s directory:<\/div>\n<div><\/div>\n<div>AGK Code:<\/div>\n<div><\/div>\n<pre style=\"background: #eeecf6; border: 1px solid #cccccc; color: #493617; padding-left: 16px;\">function ZipDirectory(sZipFileName$)\r\n if GetFileExists(sZipFileName$) = 1\r\n  DeleteFile(sZipFileName$)  endif\r\n doOnce = 0\r\n makeZip = 0\r\n repeat\r\n  if doOnce = 0\r\n   doOnce = 1\r\n   thisFile$ = GetFirstFile()\r\n  else\r\n   thisFile$ = GetNextFile()\r\n  endif\r\n  if thisFile$ = \u201c\u201d\r\n   done = 1\r\n  else\r\n   if makeZip = 0\r\n    makeZip = 1\r\n    zipFileID = CreateZip(sZipFileName$)\r\n   endif\r\n   if GetFileExists(thisFile$) = 1\r\n    zipLocation$ = GetFolder() + \u201c\/\u201d + thisFile$\r\n    AddZipEntry( zipFileID , thisFile$ , \u00a0zipLocation$)\r\n   endif\r\n  endif\r\n until done = 1\r\n if zipFileID &gt; 0\r\n  CloseZip(zipFileID)\r\n endif\r\nendfunction<\/pre>\n<div><\/div>\n<div>As you may imagine you can also do this for every directory and subdirectory for you app&#8217;s media folder. It is important to note that the directory you are working with is the write directory for the AGK app and not the read directory. The read directory for apps is where all of the media files exist that you package in with your app. On Android and iOS you do not have access to this directory without rooting\/jailbreaking the device. This shouldn&#8217;t matter because these files are the same that you packed with the app and you already have those. The write directory is a \u201csandbox\u201d area where the app is allowed to write data. This is where any file you create with the app will be stored such as data files, debug logs, etc.<\/div>\n<div><\/div>\n<div>This method is extremely helpful when developing your app and when it is actually live. When developing your app you can use this to zip up any debug logs and quickly send them to yourself. When the app is live this can be used to send error reports to you when the user experiences issues. In\u00a0<a style=\"color: #996699;\" href=\"http:\/\/www.wordspionage.com\/\" target=\"_blank\" rel=\"noopener\">Wordspionage\u00a0<\/a>we use this to send error logs whenever a fatal error occurs. This was extremely helpful in the first few months of our release because a few bugs appeared that did not appear in our extensive beta testing. It allowed us to receive data from our users automatically so they didn&#8217;t need to be bothered or actually need to hit a button to send the report. When these error reports are sent to us they also include a screen shot of the game so we can see any visual clues to the issue. This method was paramount to smoothing out the flaws in the game.<\/div>\n<\/div>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_23\" class=\"pvc_stats all  \" data-element-id=\"23\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/naplandgames.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Originally published in the TGC Newsletter &#8211; June 1, 2014 The question of transferring data from your mobile app to a server was brought up by Parry on the AGK forums and I thought I&#8217;d share my process for getting app data from a device. The problem is that Android and iOS put app data in a protected folder on the device. If you want to root or\u00a0jailbreak\u00a0the device it is easy to get at, but this process can be dangerous and complex. If you just need a peek at your app&#8217;s data then there is an easier way: add&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/naplandgames.com\/blog\/2014\/06\/16\/agk-tutorial-app-data\/\">Continue reading<span class=\"screen-reader-text\">AGK Tutorial &#8211; App Data<\/span><\/a><\/div>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_23\" class=\"pvc_stats all  \" data-element-id=\"23\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/naplandgames.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"a3_pvc":{"activated":true,"total_views":652,"today_views":0},"_links":{"self":[{"href":"https:\/\/naplandgames.com\/blog\/wp-json\/wp\/v2\/posts\/23"}],"collection":[{"href":"https:\/\/naplandgames.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/naplandgames.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/naplandgames.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/naplandgames.com\/blog\/wp-json\/wp\/v2\/comments?post=23"}],"version-history":[{"count":5,"href":"https:\/\/naplandgames.com\/blog\/wp-json\/wp\/v2\/posts\/23\/revisions"}],"predecessor-version":[{"id":333,"href":"https:\/\/naplandgames.com\/blog\/wp-json\/wp\/v2\/posts\/23\/revisions\/333"}],"wp:attachment":[{"href":"https:\/\/naplandgames.com\/blog\/wp-json\/wp\/v2\/media?parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/naplandgames.com\/blog\/wp-json\/wp\/v2\/categories?post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/naplandgames.com\/blog\/wp-json\/wp\/v2\/tags?post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}