#!/usr/bin/env python3
import os
import sys
import shutil
import zipfile
import subprocess

ver = None
lines = open(os.path.join("Src", "Lvc.h")).read().split("\n")
for l in lines:
	if l.find("APP_VERSION") >= 0:
		p = l.split()
		ver = l.split()[-1].strip("\"")
		print("Ver:", ver)
		break

if ver:
	filename = "lvc-" + sys.platform + "-v" + str(ver) + ".zip"
	print("Output:", filename)
	z = zipfile.ZipFile(filename, "w")
	if sys.platform.find("win") >= 0:
		z.write("x64Release14\\Lvc.exe", "Lvc.exe")
		z.write("..\\lib\\Lgi14x64.dll", "Lgi14x64.dll")
		z.write("..\\lib\\libpng15_14x64.dll", "libpng15_14x64.dll")
	elif sys.platform.find("linux") >= 0:
		subprocess.call(["strip", "lvc", "../Release/liblgi.so"])
		z.write("./lvc", "lvc")
		z.write("../Release/liblgi.so", "liblgi.so")
	else:
		print("Unexpected platform:", sys.platform)
	z.write("./Resources/Lvc.lr8");
	z.write("./Resources/icon64.png");
	z.write("./Resources/image-list.png")
else:
	print("Error: no version found.")
	