Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added region param to console #92

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions CASCConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,44 @@ namespace CASCConsole
enum ExtractMode
{
Pattern,
Listfile
Listfile,
Installfile
}

class CASCConsoleOptions
{
public ExtractMode Mode { get; set; }
public string ModeParam { get; set; }
public string Region { get; set; }
public string DestFolder { get; set; }
public LocaleFlags Locale { get; set; }
public string Product { get; set; }
public bool Online { get; set; }
public string StoragePath { get; set; }
public bool OverrideArchive { get; set; }
public bool PreferHighResTextures { get; set; }
public string FileTag { get; set; }
}

internal class CASCConsoleOptionsBinder : BinderBase<CASCConsoleOptions>
{
private readonly Option<ExtractMode> modeOption = new Option<ExtractMode>(new[] { "-m", "--mode" }, "Extraction mode") { IsRequired = true };
private readonly Option<string> modeParamOption = new Option<string>(new[] { "-e", "--eparam" }, "Extraction mode parameter (example: *.* or listfile.csv)") { IsRequired = true };
private readonly Option<string> region = new Option<string>(new[] { "-r", "--region" }, () => "us", "Region (example: us, eu, cn)");
private readonly Option<string> destOption = new Option<string>(new[] { "-d", "--dest" }, "Destination folder path") { IsRequired = true };
private readonly Option<LocaleFlags> localeOption = new Option<LocaleFlags>(new[] { "-l", "--locale" }, "Product locale") { IsRequired = true };
private readonly Option<string> productOption = new Option<string>(new[] { "-p", "--product" }, "Product uid") { IsRequired = true };
private readonly Option<bool> onlineOption = new Option<bool>(new[] { "-o", "--online" }, () => false, "Online extraction mode");
private readonly Option<string> storagePathOption = new Option<string>(new[] { "-s", "--storage" }, () => "", "Local game storage folder");
private readonly Option<bool> overrideArchiveOption = new Option<bool>(new[] { "-a", "--archive" }, () => false, "Override archive");
private readonly Option<bool> preferHighResTexturesOption = new Option<bool>(new[] { "-h", "--highres" }, () => false, "High Resolution Textures");
private readonly Option<string> fileTag = new Option<string>(new[] { "-t", "--tag" }, () => "US", "File tag (example: US, CN, Windows)");

public RootCommand Root { get; }

public CASCConsoleOptionsBinder()
{
Root = new RootCommand("CASCConsole") { modeOption, modeParamOption, destOption, localeOption, productOption, onlineOption, storagePathOption, overrideArchiveOption, preferHighResTexturesOption };
Root = new RootCommand("CASCConsole") { modeOption, modeParamOption, region, destOption, localeOption, productOption, onlineOption, storagePathOption, overrideArchiveOption, preferHighResTexturesOption, fileTag };
}

protected override CASCConsoleOptions GetBoundValue(BindingContext bindingContext)
Expand All @@ -56,13 +61,15 @@ protected override CASCConsoleOptions GetBoundValue(BindingContext bindingContex
{
Mode = parseResult.GetValueForOption(modeOption),
ModeParam = parseResult.GetValueForOption(modeParamOption),
Region = parseResult.GetValueForOption(region),
DestFolder = parseResult.GetValueForOption(destOption),
Locale = parseResult.GetValueForOption(localeOption),
Product = parseResult.GetValueForOption(productOption),
Online = parseResult.GetValueForOption(onlineOption),
StoragePath = parseResult.GetValueForOption(storagePathOption),
OverrideArchive = parseResult.GetValueForOption(overrideArchiveOption),
PreferHighResTextures = parseResult.GetValueForOption(preferHighResTexturesOption),
FileTag = parseResult.GetValueForOption(fileTag),
};
}
}
Expand Down Expand Up @@ -198,12 +205,12 @@ static void Main(string[] args)
var commandsBinder = new CASCConsoleOptionsBinder();

commandsBinder.Root.SetHandler((CASCConsoleOptions options) => {
Extract(options.Mode, options.ModeParam, options.DestFolder, options.Locale, options.Product, options.Online, options.StoragePath, options.OverrideArchive, options.PreferHighResTextures);
Extract(options.Mode, options.ModeParam, options.Region, options.DestFolder, options.Locale, options.Product, options.Online, options.StoragePath, options.OverrideArchive, options.PreferHighResTextures, options.FileTag);
}, commandsBinder);
commandsBinder.Root.Invoke(args);
}

private static void Extract(ExtractMode mode, string modeParam, string destFolder, LocaleFlags locale, string product, bool online, string storagePath, bool overrideArchive, bool preferHighResTextures)
private static void Extract(ExtractMode mode, string modeParam, string region, string destFolder, LocaleFlags locale, string product, bool online, string storagePath, bool overrideArchive, bool preferHighResTextures, string fileTag)
{
DateTime startTime = DateTime.Now;

Expand All @@ -212,13 +219,15 @@ private static void Extract(ExtractMode mode, string modeParam, string destFolde
Console.WriteLine("Extract params:");
Console.WriteLine(" Mode: {0}", mode);
Console.WriteLine(" Mode Param: {0}", modeParam);
Console.WriteLine(" Region: {0}", region);
Console.WriteLine(" Destination: {0}", destFolder);
Console.WriteLine(" LocaleFlags: {0}", locale);
Console.WriteLine(" Product: {0}", product);
Console.WriteLine(" Online: {0}", online);
Console.WriteLine(" Storage Path: {0}", storagePath);
Console.WriteLine(" OverrideArchive: {0}", overrideArchive);
Console.WriteLine(" PreferHighResTextures: {0}", preferHighResTextures);
Console.WriteLine(" Tag: {0}", fileTag);

Console.WriteLine("Loading...");

Expand All @@ -228,7 +237,7 @@ private static void Extract(ExtractMode mode, string modeParam, string destFolde
CASCConfig.LoadFlags |= LoadFlags.Install;

CASCConfig config = online
? CASCConfig.LoadOnlineStorageConfig(product, "us")
? CASCConfig.LoadOnlineStorageConfig(product, region)
: CASCConfig.LoadLocalStorageConfig(storagePath, product);

CASCHandler cascHandler = CASCHandler.OpenStorage(config, bgLoader);
Expand Down Expand Up @@ -268,6 +277,24 @@ private static void Extract(ExtractMode mode, string modeParam, string destFolde
ExtractFile(cascHandler, 0, file, destFolder);
}
}
else if (mode == ExtractMode.Installfile)
{
Wildcard wildcard = new Wildcard(modeParam, true, RegexOptions.IgnoreCase);

var installFiles = cascHandler.Install.GetEntriesByTag(fileTag);
var build = cascHandler.Config.BuildName;
int numFiles = installFiles.Count();

foreach (var file in installFiles)
{
if (cascHandler.Encoding.GetEntry(file.MD5, out EncodingEntry enc) && wildcard.IsMatch(file.Name))
{
cascHandler.SaveFileTo(enc.Keys[0], destFolder, file.Name);

Console.WriteLine("Extracting '{0}'...", file.Name);
}
}
}

Console.WriteLine("Extracted.");

Expand Down