Lua Love2D - How can I make it download a file? - download

Title. It's only allowed to save to a certain directory, but is there a way of making an executable made with it update itself? I've got the code to check if it's out of date (HttpGet), but not sure how to intall the newer update.
Main reason is people are complaining about having to repeatedly redownload my RPG. Would it be easier to package it with a C# auto-Updater they can run?

You can not make the .love file "update itself". That is not possible, unless you use the operative system's package manager or something similar (apt-get in Ubuntu, the app store on mac, and whatever microsoft uses, if it has it).
If you don't want to do that, then the second best way to make that work would be making your love2d executable a "shell"; an "empty game" that simply downloads stuff from the internet, and later on it executes some function that initializes everything, including the proper game.
As jpjacobs says, you can download stuff from the web using LuaSocket (which is already included in LÖVE 0.7). For example, this is how you download a png (I've copied the code from here):
if not love.filesystem.exists("expo.png") then
local http = require("socket.http")
local b, c, h = http.request("http://love2d.org/w/images/e/e3/Resource-AnalExplosion.png")
love.filesystem.write("expo.png", b)
end
There's also a way to uncompress data using the GNU unzip algorithm using pure lua. It's implemented by the /AdvTiledLoader/external/gunzip.lua file in Kadoba's Advanced TileLoader.
So I guess you can make a game that:
Starts by reading a file called version.lua, and comparing it to a file in your server (http://www.your-server.com/latest-version-number). That file simply contains a number, like "48".
If no file and server could not be contacted, then error "could not download game".
If no file, or current version < latest version from the server, download zip file from server (http://www.your-server.com/latest.zip)
If latest.zip downloaded successfully, erase everything inside the /latest directory and uncompress latest.zip on the new latest. Update version.lua with the new version (return 48)
Detect when you are working offline - If could not download latest.zip or version, but there's already a version.lua and latest folder, give just a warning, not an error.
Require the file that contains the real game; probably something like require 'latest.main'
Notes:
I'm not familiar with luasocket. It is possible that there's a way to get the 'last updated' date from http://www.your-server.com/latest.zip, so you can simply get rid of the latest-version-number stuff.
I haven't used gunzip.lua myself. I don't know how it handles multiple files, or directories.

My first guess would be using LuaSocket. You can have a small file containing the current version number, have that downloaded on startup, and then decide whether an upgrade is necesarry or not.

Related

Why doesn't the PDW copy some files when updating an existing installation?

I have a fairly large application (~750k LOC) that I distribute using the Package and Deployment Wizard. I fully understand that it would be nice to migrate to .NET (that ain't happening - see the code size above), and that the PDW is deeply flawed. However, for the most part I've made it work well for my end users, by customizing the Setup1 application, writing a menu-driven wrapper for the Setup application, and by running it in silent mode. (Note that the problem I'm about to describe occurred even before I started using silent mode.)
The issue I'm having is that my application requires quite a few auxiliary files, which I've added to the PDW project in the "Included files" section. When a user does a clean installation (either from scratch, or after un-installing a previous installation), everything works fine. However, if they simply run the installer to update the existing installation, the executable file and any OCXs I've updated get copied over the previous versions just fine, but my auxiliary files don't - I have to have the user manually delete them, and then the Setup1 program will re-install them as it should.
I've checked in the Setup.lst file, and all of the files are listed there, with their current date stamps. In fact, in my "BuildAll.bat" file, I do the Windows equivalent of a "touch" (copy /b "TheFile.dat" +,,) to force the date stamp to be current. However, if the file exists on the target machine, it won't be over-written even though it's older. There are no errors reported, either visibly or in the .LOG file (which is required if using the silent option).
A couple of additional points: Some of the auxiliary files are themselves VB6 applications - just the .exe files. Those do get copied correctly if they're newer than the existing files. Other than being files with internal versioning information, there's no difference between them and the other auxiliary files (which are things like media files, or text-based .txt or .dat files).
So, what's going on, and how do I fix it (besides moving to Inno or some other solution that won't work for me...)? Thanks in advance for any help!
~~
Mark Moulding

Script to remove file from a single target

We're building an app that has different versions for different countries.
As part of a localisation effort I'm aiming to write a script that swaps certain asset files with another based on the language parameter.
I've written a python script for this using a python library, but that has a bug where on editing the files xcode doesn't really recognise the structure anymore and we have to restart xcode.
So the newer approach is to use this ruby gem.
I am fetching the project and I can access the files
project = Xcodeproj::Project.open(project_path)
target = project.targets.first
files = target.source_build_phase.files.to_a.map
But I can't find anything in the documentation where it would allow me to remove a file from just one target.
I have thought about creating a new target and adding all the files except the one I want deleted.
But I think that seems overkill for the issue we're trying to solve.

Connecting dots from self-contained Java application to Mac OS installation

I am not a Mac owner and am putting myself through a crash course to get up to speed (e.g., reading "Switching to the Mac"), to give you an indication of my current level of understanding. The access I have to a physical Mac is limited, so I am trying to connect as many dots as possible before my next session with my friend's computer.
I have: a file folder containing all resources needed for a self-contained application written with Java (OpenJDK 11, JavaFX 11). The JLINK tool was successfully used to create this file folder, and it holds all necessary Java libraries as well as the code I wrote for the application. The executable resides in a subfolder: /bin. The program runs perfectly well on the Mac when the executable is run.
I want: something that is easy to download, install and run.
I'm unclear about what needs to be done to get this. The road map seems to have two main steps:
the file folder needs to be converted into something that responds as if it were an application (e.g., a Bundle? or an .app?)
the resulting folder-as-executable can be shipped via either .dmg or .pkg
For the second part, I've researched and found tools such as Packages or create-dmg. It seems to me these tools are pretty straightforward and shouldn't be too difficult to learn to use. (Just have to pick one or the other or something similar.)
For the first part, I'm on shaky conceptual ground. I've found info about Bundles, but no tutorials, walk-throughs or examples. It looks like a key step is understanding how to make a proper Info.plist file, but doing this properly looks tricky. Also, I'm not clear on how the resulting Bundle will become an .app file or if it needs to, or if there is another, more direct way to make my file folder be viewed by the OS as an application.
Some hand-holding or references to tutorials or even assurance that I am on the right track (if that is the case) would be much appreciated. Thanks!
The Java Deployment guide from Oracle relies heavily on ANT, but doesn't cover the case of a self-contained, customized JVM via JLINK well enough for me to decipher. So, I've taken the approach of trying to learn/understand the necessary steps using command-line commands.
While creating a Bundle is certainly an option, there is an easier way.
Step one is to make an .app manually. An answer to this question: "How to make a Mac OS X .app with a shell script?" goes over the basic steps. The Java file system that results from jlinking has a folder /bin in which there is a bash file that runs the program. This file should be moved to the outermost folder, and it should be named the desired name of the application. The bash file itself will have to be edited and "/bin" added to the address in last command so that the executable will be found. In addition, the folder itself will have to be renamed to be the same as the bash file, but with .app added as an extension.
The next thing I wanted to have was a custom icon. The question "Include icon in manually created app bundle" shows how to do this.
For the next step I made use of the program "Packages". I'm a bit confused about where I downloaded this from (there seem to be multiple sites), but here is a link to the manual. This tool allowed me to create a .pkg file that, when executed, installs my .app in the Applications folder. Then I compressing the .pkg file (to .zip) and made it available at a URL for downloading.
I've had a friend do a test download and install, and the program works!
This isn't meant to be a complete tutorial, and there are a few steps more that I want to figure out pertaining to sandboxing and sealing, but I believe this is a reasonable roadmap that can be used for simpler jlinked Java applications for Mac distribution.

Encoding of SMS-files from Nokia backup (.nbf)?

I am using a Mac and have a Nokia phone. Therefore I cannot sync it with my computer, but I found out, that making a backup on the creates a .nbf-file, which contains all the data I want (contacts and messages).
The contacts are stored easily accessible as vCards, so that's cool. Unfortunately the messages are stored each text separately in one file, which looks pretty weird when I open it with a text editor (for example TextWrangler). I can see the numbers and the text, but no information about date.
I uploaded the file here: http://www.4shared.com/file/7LNsuPbF/00000A123EB640F500002010005000.html
I already tried out different encodings, but it never looks good.
Maybe someone has a clue how to read that file? Could it be encrypted or something?
Try https://sourceforge.net/projects/nbuexplorer/ - it should be able to open .nbf files.
It is/was a C# project, and it only provides Windows exe as release download, however, I could get this .exe to run on Ubuntu 18.04 using mono; and I could also get the project sources to compile on Ubuntu using xbuild (the result again being an .exe file that can be run with Mono), see comments in my build script get-nbuexplorer.svn.sh.

How to mimic DropBox functionality with Ruby script?

I would like to upload documents to GoogleDocs every time the OS hears that a file was added/dragged/saved in a designated folder, just the way DropBox uploads a file when you save it in the DropBox folder.
What would this take in Ruby, what are the parts?
How do you listen for when a File is Saved?
How do you listen for when a File is added to a Folder?
I understand how to use the GoogleDocs API and upload things once I get these events, but I'm not sure how this would work.
Update
While I still don't know how to check if a file is added to a directory, listening for when a file is saved is now dirt simple, thanks to Guard for ruby.
If I were faced with this, I would use something like git or bzr to handle the version checking and just call add then commit from your script and monitor which files have changed (and therefore need to be uploaded).
This adds the benefit of full version control over files and it's mostly cross platform (if you include binaries for each platform).
Note this doesn't handle your listening problem, just what you do when you know something has changed. You could schedule the task (via various routes) but I still like the idea of a proper VCS under the hood.
I just found this: http://www.codeforpeople.com/lib/ruby/dirwatch/
You'd need to read over it as I can't vouch for its efficiency or reliability. It appears to use SQLite, so it might be better just to manually check once every 10 seconds (or something along those lines).
Ruby doesn't include a built-in way to "listen" for updates to files. If you want to stick to pure Ruby, your best bet would be to perform the upload on a fixed schedule (say every 5 minutes) regardless of when the file is saved.
If this isn't an acceptable alternative, you could try writing the app (or at least certain parts of it) in Java, which does support this type of thing. Take a look at JRuby for integrating the Ruby and Java portions of your app.
Here is a pure ruby gem:
http://github.com/TwP/directory_watcher
I don't know the correct way of doing this, but a simple hack would be to have a script running in the background which checks the contents of a bunch of folders every n minutes and uses the associated timestamps to determine if the file was modified in that span of time
You would definitely need some native OS code here, to write the monitoring service/client. I'd select C++ if you want it to be cross platform. If you decide to go with .Net, for example, you can use the FileSystemWatcher class to achieve what you need (documentation and here's a related article).
Kind of an old thread, but I am faced with doing something similar and wanted to throw in my thoughts. The route I'm going is to have a ruby script that watches a given directory and checks the timestamps. Once all files have been uploaded, the script saves the latest timestamp and then polls the directory again, checking if any files/folders have been added. If files are found, then the script uploads them and updates the global timestamp, etc...
The downside is that setting up a ruby script to run continually (or as a service) is somewhat painful. But it's not an overwhelming task, just needs to be thought out properly.
Also depends on if your users are competent enough to have ruby installed or if you have to package everything up into a one-click installer as well. That, to me, is the hardest part to figure out.

Resources