-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathProgram.cs
More file actions
105 lines (94 loc) · 3.99 KB
/
Program.cs
File metadata and controls
105 lines (94 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.IO;
using System.Diagnostics;
using System.CodeDom;
namespace VRCDynamicPoster;
public class Program
{
public static readonly string ASSET_PATH = "asset";
public static readonly string VRC_WORLD_BASE_URL = "https://vrchat.com/home/world/{id}";
public static readonly string VRC_AVATAR_BASE_URL = "https://vrchat.com/home/avatar/{id}";
public static readonly int LIMIT_ENTRY_NUM = 128;
public static readonly string DST_DIR = "dst";
public static readonly string PREVIEW_HTML_NAME = "index.html";
public static readonly string PREVIEW_IMAGE_NAME = "index.bmp";
private static void Main(string[] args)
{
// デフォルト or コマンドラインから設定
var assetDir = args.Length > 2 ? args[1] : ASSET_PATH;
var worldBaseUrl = args.Length > 3 ? args[2] : VRC_WORLD_BASE_URL;
var avatarBaseUrl = args.Length > 4 ? args[3] : VRC_AVATAR_BASE_URL;
var limitNum = args.Length > 5 ? int.Parse(args[4]) : LIMIT_ENTRY_NUM;
// 現状帰る必要なさそう
var dstDir = DST_DIR;
var previewHtmlName = PREVIEW_HTML_NAME;
var previewImageName = PREVIEW_IMAGE_NAME;
Console.WriteLine("== VRCDynamicPoster ==");
Console.WriteLine($"{nameof(assetDir)}={assetDir}");
Console.WriteLine($"{nameof(worldBaseUrl)}={worldBaseUrl}");
Console.WriteLine($"{nameof(avatarBaseUrl)}={avatarBaseUrl}");
Console.WriteLine($"{nameof(limitNum)}={limitNum}");
Console.WriteLine($"{nameof(dstDir)}={dstDir}");
Console.WriteLine($"{nameof(previewHtmlName)}={previewHtmlName}");
Console.WriteLine($"{nameof(previewImageName)}={previewImageName}");
// 前回出力を破棄
if (Directory.Exists(dstDir))
{
Directory.Delete(dstDir, true);
}
Directory.CreateDirectory(dstDir);
// ファイル一覧を取得
var entries =
Directory.GetFiles(assetDir)
.Select((srcDir, i) => new Entry(i, srcDir, dstDir, worldBaseUrl, avatarBaseUrl))
.ToArray();
Console.WriteLine("encode_files={");
foreach (var e in entries)
{
Console.WriteLine($"\t{e},");
}
Console.WriteLine("}");
if (entries.Length == 0)
{
Console.WriteLine($"entry not found. assetDir={assetDir}");
return;
}
// Limit確認。削る
if (entries.Length >= limitNum)
{
Console.WriteLine($"[WARN] entries > limitNum({limitNum})");
entries = entries.Take(limitNum).ToArray();
}
// Preview生成
var preview = new Preview(entries);
var htmlText = preview.TransformText();
var htmlPath = Path.Combine(dstDir, previewHtmlName);
File.WriteAllText(htmlPath, htmlText);
Console.WriteLine($"preview page: {htmlPath}");
// asset/worldの画像コピー
foreach (var e in entries)
{
e.Copy();
Console.WriteLine($"copy: {e.ImageSrcPath} => {e.ImageDstPath}");
}
// エンコードした画像を生成
var encodeImagePath = Path.Combine(dstDir, previewImageName);
Console.WriteLine($"encode image: {encodeImagePath}");
TextImageGenerator.Encode(encodeImagePath, entries, limitNum);
// デコードテスト
var decodeEntries = TextImageGenerator.Decode(Path.Combine(dstDir, previewImageName)).ToArray();
bool isVerifyPass = true;
foreach (var (encode, decode) in entries.Zip(decodeEntries))
{
var isEquals = encode.Id.Equals(decode);
if (!isEquals)
{
isVerifyPass = false;
Console.WriteLine($"[FAIL] encode: {encode.Id}, decode: {decode}");
}
}
Console.WriteLine($"decode test: {(isVerifyPass ? "PASS" : "FAIL")}");
Console.WriteLine();
Console.WriteLine("All processes are complete.");
}
}