resource files in Haaf's game engine - visual-c++

I'm working with a program that uses Haaf's game engine which uses resource files that are saved as a .nsf format. These files are actually just zip files with a folder hierarchy in them and a resources.nsr file which just has information about each file.
The resources.nsf file has folders and an .nsr file setup like this:
|_resource.nsf
|_images
||-some .png files
|_sounds
||-some sound files
|-resource.nsr
The format of the .nsr file is as follows:
;TEXTURES-------------------------------------
Texture background
{
filename = images\background.png
}
;---------------------------------------------
Texture a
{
filename = images\a.png
}
;---------------------------------------------
Texture b
{
filename = images\b.png
}
....more textures
;SPRITES--------------------------------------
Sprite backgroundSpr
{
texture = background
rect = 0, 0, 1024, 768
}
....more sprites
In the images folder I found a thumbs.db file, and when I opened it the first line had Mac OS X printed in it. I assume that the zip file originated on an OS X system.
I have tried zipping up a new resource file with 7zip and windows compression. The site for Haaf's game engine recommends using pkzip, but that costs money now so I cannot obtain a copy of it.
Is there a way I can repack my resource file and have it work under Windows 7 x64?

Winrar works if you compress it to a zip file, this will allow the game engine to use the resource files properly.

Related

How to get acces to file in the same folder of the game (Godot engine)

So i wanted to load external file in my godot game but I can't find any answer. I want to load file (sound, image, ...) in the same folder of the game (.exe).
By the way I can always do it directly include all the file in the engine but it's more easy to modify the external file than file in the editor
You can use OS.get_executable_path() to get the path of the executable. Except, it will give you the path to the Godot executable if you are running from the editor.
You can check if your code is running from the editor with OS.has_feature("standalone").
And of course, you don't really want the path to the executable, but to the folder it is in. So we use get_base_dir.
Like this:
if OS.has_feature("standalone"):
var folder := OS.get_executable_path().get_base_dir()
Also be aware of OS.get_user_data_dir() which gives you an appropriate folder for your game depending on the operating system (there is also where the "logs" folder will be). Plus OS.get_user_data_dir() will work even when running form the editor, and it gives you a folder path directly.
Then we can either build a path to another file in the same folder:
if OS.has_feature("standalone"):
var path := OS.get_executable_path().get_base_dir()
var file_name := folder.plus_file("my_file.png")
Or we can enumerate files:
if OS.has_feature("standalone"):
var path := OS.get_executable_path().get_base_dir()
var dir = Directory.new()
if dir.open(path) == OK:
dir.list_dir_begin()
var file_name:String = dir.get_next()
while file_name != "":
if not dir.current_is_dir():
if file_name.get_extension() == "png":
print("Found file: " + file_name)
file_name = dir.get_next()
else:
print("An error occurred when trying to access the path.")
Now, you want to load them. Except load et.al. won't work because they are not resources in your project.
You can read the contents of a file into a buffer like this:
var file := File.new()
file.open(file_name, File.READ)
var buffer := file.get_buffer(file.get_len())
file.close()
Then from the buffer you can create an Image like this:
var my_image := Image.new()
my_image.load_png_from_buffer(buffer)
If you happen to need a Texture you can do this:
var my_texture := ImageTexture.new()
my_texture.create_from_image(my_image)
I'll also mention that you can set the flags of the Texture.
And for sound…
I will point you to GDScriptAudioImport because, sadly, it is not as straightforward.
And as you can imagine anything else you want to load from external files will different code to support it.
By the way I can always do it directly include all the file in the engine but it's more easy to modify the external file than file in the editor
You can always edit files in the project folder with any other external software and when you switch back to Godot it will detect the changes and re-import. So you don't need to modify anything within Godot.
And for any other software modifying files in the project folder should not be any harder than modifying files located elsewhere.

Im am getting FileNotFoundError when trying to create a for in loop

I am making an image classifier. I have successfully created the folders and I manually placed the .txt files which has links to images from google inside each folder.
I am now trying to download the images from each .txt file either into a folder inside each folder category, or into each category folder that also has the .txt file, however i keep getting errors. please help.
I manually placed the .txt files in each of the folders as they was in the parent folder name as PLANTS but this has not made a difference.
I expected to get all the images downloaded in their respective folders from the .txt files with google image links but it is not working, whether the .txt is inside the main PLANTS FOLDER or inside each category folder which is inside the PLANTS folder
instead i get the below errors
FileNotFoundError
please see attached screen shot
&
Long filenames or paths with spaces are supported by NTFS in Windows NT. However, these filenames or directory names require quotation marks around them when they are specified in a command prompt operation. Failure to use the quotation marks results in the error message.
for i in range(len(folders)):
path = "content/gdrive/My Drive/Colab Notebooks/Flowers/PLANTS"
#for creating directory we need path class object so below this:
dest_for_creating_directory = path/folders[i]
#for searchi directory which have spaces we need doubleQuotations that
#why user below one in download image function instead of dest.
dest_for_searching_directory = path+"/"+folders[i]
Note: its better practice to write folder/file name without space more info

Cloning images with Python 3+Pillow in order to strip hidden metadata

I have a client that created several large PDFs, each containing hundreds of images within them. The images were created with a program that adds unique info to each file; random binary data was placed in some file headers, some files have data disguised as image artifacts, and general metadata in each image. While I'm unfamiliar with the program, I understand that it's a marketing software suite of some sort so I assume the data is used for tracking online distribution and analytics.
I have the source files used to create the PDFs and while I could open each image, clone its visual data, strip metadata and re-compress the images to remove the identification data, I would much rather automate the process using Pillow. The problem is, I'm worried I could miss something. The client is hoping to release the files from behind an online username, and he doesn't want the username tied to this program or its analytical tracking mechanisms.
So my question is this: how would I clone an image with Pillow in a way that would strip all identifying metadata? The image files are massive, ranging from 128MB to 2GB. All of the images are either PNG uncompressed or JPEG files with very mild compression. I'm not married to Pillow, so if there's a better software library (or standalone software) that better suits this, I'll use it instead.
Just use ImageMagick as installed on most Linux distros and available for macOS and Windows. So, in Terminal, strip the metadata from an input file and resave:
magick input.jpg -strip result.jpg
If you want to do all JPEGs in current directory:
magick mogrify -strip *.jpg
Or maybe you want to change the quality a little too:
magick mogrify -quality 82 -strip *.jpg
Copying the pixel data to a new image should remove all metadata and compressing the image slightly as a jpeg should remove steganographic tracking data.
You may have to modify the load/copy/save methods to deal with large files. Also pay attention to the PIL file size limitations. Opacity in png files isn't handled here.
import os
from PIL import Image
picture_dir = ''
for subdir, dirs, files in os.walk(picture_dir):
for f in files:
ext = os.path.splitext(f)[1]
if( ext in ['.jpg','.jpeg','.png'] ):
full_path = os.path.join(subdir, f)
im = Image.open(full_path)
data = list(im.getdata())
no_exif = Image.new('RGB', im.size) # not handling opacity
no_exif.putdata(data) # should strip exif
out_path = full_path.split(ext)[0] + 'clean.jpg'
no_exif.save(out_path, 'JPEG', quality=95) # compressing should remove steganography

JavaFX ExtensionFilter not working properly in ubuntu

I have created a small application in javafx wherein one has to choose JPG,PNG or GIF image to work with. Here's the code am using to filter the files :
FileChooserBuilder fcb = FileChooserBuilder.create();
FileChooser fc = fcb.title("Open Dialog").initialDirectory(new File(currentDir)).build();
//Set extension filter
FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter("JPG files (*.jpg)", "*.JPG");
FileChooser.ExtensionFilter extFilterPNG = new FileChooser.ExtensionFilter("PNG files (*.png)", "*.PNG");
FileChooser.ExtensionFilter extFilterGIF = new FileChooser.ExtensionFilter("GIF files (*.gif)", "*.GIF");
fc.getExtensionFilters().addAll(extFilterJPG, extFilterPNG, extFilterGIF);
selectedFile = fc.showOpenDialog(link);
This code works fine in Windows 7. But while using it in Ubuntu it doesn't show me all files with JPG, PNG or GIF. It shows a few, but I couldn't exactly make out why it does that.
Ubuntu and unix like systems are case sensitive. So it's filtering for "*.JPG" and maybe you have files with uppercase or lowercase extension. So the file won't match in the case of files with lowercase extension.
In windows, there is no problem, because it isn't case sensitive, I mean, one.jpg it's the same that one.JPG.
So to fix it add the extension in lowercase in the constructor of the ExtensionFilter.
FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter("JPG files (*.jpg)", "*.JPG", "*.jpg");
Hope it helps

Updating .txt file in J2ME located in Binary package

I have developed J2ME application that read data from product.txt file located in binary package using following code
InputStream is = getClass().getResourceAsStream("/product.txt");
int size = is.available();
byte bytes[] = new byte[size];
is.read(bytes, 0, size);
str = new String(bytes, 0, size);
Now I want's to update product.txt file located in binary package using J2ME code.
I have tried Following code to get relative path of product.txt
String path=getClass().getResource("/product.txt").getPath();
But it does not works on J2ME platform.
How to get relative path Of product.txt file located in binary package?
You can't change a file that is baked in to the jar. You'll notice that there is no equivalent of getResourceAsStream() that offers an OutputStream.

Resources