1

WWW.LoadFromCacheOrDownload(string url, Hash128 hash) uses hash128 but there is no proper documentation regarding hash, how to use this and why this is important?

Is it related to securing the url in above function or something else?

Aryaman Gupta
  • 616
  • 1
  • 8
  • 20
  • I'm not entirely sure but from what research just told me I believe that object to be a 128 bit hash of the object (or file) you're downloading from the given url. I'm probably wrong and if so then please let me know. The point is to determine whether or not the framework needs to download the object or use the one in the cache. – Richard Barker Jun 27 '16 at 15:01
  • I want to ask one thing if I directly put the url in WWW.LoadFromCacheOrDownload is it safe or potential hacker might know my url and steal data? @Richard – Aryaman Gupta Jun 27 '16 at 17:36
  • I don't know. That's a unity thing. If it's touching the internet then yeah a hacker could very probably be able to see the data. However, a url (which maps to an ip) isn't very helpful if the actual data is transmitted through SSL (assuming you're using http to transfer your data) meaning it's encrypted before transmitting. That won't happen if your data is on the query string or apart of the url. Again it's a unity thing and, while I've used unity, I'm not experienced with it so my comments may not be very valuable which is why they're comments and not an answer. I do know .Net though.. – Richard Barker Jun 27 '16 at 20:16

1 Answers1

1

The whole point is to make (reasonably) sure that you're not caching a different version of the same file.

When you first call LoadFromCacheOrDownload, it will look into the cache, and see that the URL you're requesting hasn't been downloaded before. When you call it the second time, unless the cache has been cleared in the meantime, you're going to avoid the download and go directly to cache.

When you release a new version of your game, the file is still (possibly) in cache. If the file changed in the meantime, you need to ensure that it will be downloaded again - that's what version is for; every time you update a resource, just increment the version.

Finally, crc (or hash) is a way to ensure that the file in the cache is not corrupt. For example, the user might have manually changed the file, or the file might have been corrupted by a disk error (more common than you might think). Unity will see that the file doesn't match the hash and redownload. It's not hard to compute a CRC-32 hash, and you'll find plenty of tools for doing this for you.

Luaan
  • 62,244
  • 7
  • 97
  • 116