70 lines
1.6 KiB
D
Executable File
70 lines
1.6 KiB
D
Executable File
#!/usr/bin/env -S ldc2 -run
|
|
|
|
/**
|
|
* @file emoji_gen.d
|
|
* @author marisa (marisa@fwmari.net)
|
|
* @brief Main program for generating emoji pack metadata
|
|
* @version 0.1
|
|
* @date 2023-11-26
|
|
*
|
|
* Copyright (c) 2024 Marisa
|
|
*
|
|
*/
|
|
|
|
module emoji_gen;
|
|
|
|
import std.stdio;
|
|
import std.file;
|
|
import std.path;
|
|
import std.json;
|
|
import std.algorithm.searching;
|
|
|
|
enum permittedExtensions = "jpg jpeg gif png";
|
|
|
|
int main(string[] args) {
|
|
if (args.length < 2) {
|
|
writeln("Usage: ", args[0], " <directory>");
|
|
return 1;
|
|
}
|
|
|
|
string dirPath = args[1];
|
|
assert(exists(dirPath));
|
|
assert(isDir(dirPath));
|
|
|
|
string outFile = buildPath(dirPath, "pack.json");
|
|
|
|
string[string] files;
|
|
|
|
foreach (entry; dirEntries(dirPath, SpanMode.shallow)) {
|
|
string name = baseName(entry.name);
|
|
|
|
if (!entry.isFile)
|
|
continue;
|
|
|
|
if (!permittedExtensions.canFind(extension(name)[1 .. $])) {
|
|
writeln("Not including ", name, " as it isn't a permitted file");
|
|
continue;
|
|
}
|
|
|
|
writefln("Adding :%s: -> %s", stripExtension(name), name);
|
|
files[name.stripExtension] = name;
|
|
}
|
|
|
|
if (files.length <= 0) {
|
|
writeln("No images found, not creating pack");
|
|
return 1;
|
|
}
|
|
|
|
JSONValue pack;
|
|
pack["pack"] = ["can-download": false];
|
|
pack["files"] = files;
|
|
pack["files_count"] = files.length;
|
|
|
|
writeln("Found ", files.length, " images");
|
|
writeln("Writing pack information to ", outFile);
|
|
File(outFile, "w").write(pack.toPrettyString());
|
|
// write(outFile, pack.toPrettyString().ptr);
|
|
|
|
return 0;
|
|
}
|