private static void RipAvatar(ApiAvatar avatar) { if (avatar == null || avatar.id == null || avatar.name == null || avatar.authorId == null || avatar.authorName == null) { Debug.LogLine("[ERROR ] Avatar is NULL!", ConsoleColor.Red, false, true); return; } if (!protector.TryStartSession()) { return; } try { string path = $"{assetsPath}\\Avatars\\{avatar.id.Guid.ToString("N")}"; bool refreshMetaData = cmd.type == CommandType.Refresh; // Save avatar to database if (database.AddAvatar(avatar, refreshMetaData)) { // Write assetfile, thumbnail, and description if (RipperTools.WriteAvatar(avatar, path, !refreshMetaData, refreshMetaData)) { // Inform user Debug.LogLine($"[INFO ] Downloaded avatar {avatar.name}, created by {avatar.authorName}", ConsoleColor.Green, true); } } else { Debug.LogLine($"[INFO ] Skipped avatar {avatar.name}, created by {avatar.authorName}: Already in database / invalid meta-data!", ConsoleColor.Green, true); } } catch (Exception ex) { Debug.LogLine($"[EXCEPTION ] Failed to rip avatar {avatar.name}, created by {avatar.authorName}:\t{ex.Message}", ConsoleColor.Red, true, true); } finally { protector.EndSession(); } }
private static void Main(string[] args) { // Register exit handler Console.CancelKeyPress += new ConsoleCancelEventHandler(KeyHandler); cmd = ParseArgs(args); #if !DEBUG if (cmd.type == CommandType.None) { PrintHelpMessage(); return; } #else inputFile = "avatars.txt"; cmd.type = CommandType.Download; cmd.ignoreDeleted = true; #endif Debug.LogText("[INFO ] Opening database...\t\t\t"); database = new OldVrcDb(); if (!database.Open($"URI=file:{Directory.GetCurrentDirectory()}\\data.db")) { Debug.LogLine("ERROR", ConsoleColor.Red); return; } Debug.LogLine("Done.", ConsoleColor.Green); Debug.LogText("[INFO ] Initializing database...\t\t\t"); if (!database.Init()) { Debug.LogLine("ERROR", ConsoleColor.Red); database.Close(); return; } Debug.LogLine("Done.", ConsoleColor.Green); client = new ApiClient(); var idsToDownload = new List <VrcId>(); // Read database { Debug.LogText("[INFO ] Reading ids from database...\t\t"); var ids = cmd.ignoreDeleted ? database.GetAllIds(false) : database.GetAllIds(); Debug.LogLine($"Got {ids.Length} ids", ConsoleColor.Green); downloadedAssets.AddRange(ids); } if (cmd.type == CommandType.ExtractIds) { File.WriteAllLines("extractedids.txt", downloadedAssets.Select(i => i.ToString())); foreach (var id in downloadedAssets) { Console.WriteLine(id); } return; } { Debug.LogText("[INFO ] Reading deleted ids from database...\t"); var ids = database.GetAllIds(true); Debug.LogLine($"Got {ids.Length} ids", ConsoleColor.Green); inactiveIds.AddRange(ids); } if (cmd.type == CommandType.Download) { // Read input avatar list Debug.LogText($"[INFO ] Reading file...\t\t\t\t"); string text = File.ReadAllText(inputFile); Debug.LogLine($"Read {ToolBox.FormatLog((ulong)text.Length, 'B')}", ConsoleColor.Green); Debug.LogText("[INFO ] Parsing file...\t\t\t\t"); if (!RipperTools.TryGetVrcIdList(text, out var ids)) { Debug.LogLine("ERROR", ConsoleColor.Red); PrintHelpMessage(); Cleanup(); return; } Debug.LogLine($"Got {ids.Length} ids", ConsoleColor.Green); Debug.LogText("[INFO ] Queueing ids...\t\t\t\t"); idsToDownload.AddRange(ids); Debug.LogLine("Done.", ConsoleColor.Green); Debug.LogText("[INFO ] Removing known ids...\t\t\t"); idsToDownload = idsToDownload.Except(downloadedAssets).Except(inactiveIds).ToList(); Debug.LogLine("Done.", ConsoleColor.Green); } else if (cmd.type == CommandType.Update) { idsToDownload.AddRange(downloadedAssets); } else if (cmd.type == CommandType.Refresh) { idsToDownload.AddRange(downloadedAssets); downloadedAssets.Clear(); } Debug.LogText("[INFO ] Removing duplicates...\t\t\t"); inactiveIds = inactiveIds.Distinct().ToList(); idsToDownload = idsToDownload.Distinct().ToList(); downloadedAssets = downloadedAssets.Distinct().ToList(); Debug.LogLine("Done.", ConsoleColor.Green); // TODO IMPLEMENTME: currently just lists found vrchat ids if (cmd.type == CommandType.Attach) { while (!CleanupDone()) { if (RipperTools.TryGetVrcCacheEntries(true, out var entries)) { entries.RemoveAll(m => downloadedAssets.Contains(m.id)); foreach (var entry in entries) { Debug.LogLine(entry.id.ToString()); downloadedAssets.Add(entry.id); } Thread.Sleep(libParseDelayTimeInMs); } else { Thread.Sleep(libCheckDelayTimeInMs); } } } else { Debug.LogText("[INFO ] Starting requets...\t\t\t"); Debug.LogLine($"{idsToDownload.Count} ids queued", ConsoleColor.Green); foreach (var id in idsToDownload) { if (CleanupDone()) { break; } try { switch (id.IdType) { case VrcId.VrcIdType.Avatar: client.GetAvatarById(id, RipAvatar, DisableId); Thread.Sleep(apiDelayTimeInMs); break; case VrcId.VrcIdType.World: client.GetWorldById(id, RipWorld, DisableId); Thread.Sleep(apiDelayTimeInMs); break; case VrcId.VrcIdType.User: case VrcId.VrcIdType.LegacyUser: //database.AddUser(); //Thread.Sleep(apiDelayTimeInMs); break; default: Debug.LogLine($"[UNPARSABLE] Skipping {id}", ConsoleColor.Yellow); continue; } } catch (Exception ex) { Debug.LogLine($"[EXCEPTION ] Failed to get {id}:\n\t{ex.Message}", ConsoleColor.Red, false, true); break; } } } // Exit after all processes are done protector.ExitAfterProcs(); Cleanup(); }