Skip to content

Commit a4eb711

Browse files
committed
update consoleapp to use latest
1 parent 4d8f867 commit a4eb711

File tree

4 files changed

+96
-104
lines changed

4 files changed

+96
-104
lines changed

EIV_DataPack.Console/EIV_DataPack.ConsoleApp.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="EIV_DataPack" Version="1.0.3.1" />
12-
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
13-
<PackageReference Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.22272.1" />
11+
<PackageReference Include="CommandLineParser" Version="2.9.1" />
12+
<PackageReference Include="EIV_DataPack" Version="1.1.0" />
1413
</ItemGroup>
1514

1615
</Project>

EIV_DataPack.Console/Options.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using CommandLine;
2+
3+
namespace EIV_DataPack.ConsoleApp;
4+
5+
public class CommonOptions
6+
{
7+
[Option('f', "file", Required = true, HelpText = "The file to to manipulate.")]
8+
public string File { get; set; } = string.Empty;
9+
}
10+
11+
[Verb("list", HelpText = "List all files from the .eivp file.")]
12+
public class ListOptions : CommonOptions;
13+
14+
[Verb("fversion", HelpText = "Show the eivp file version.")]
15+
public class FileVersionOption : CommonOptions;
16+
17+
[Verb("create", HelpText = "Create and add all files to the .eivp file.")]
18+
public class CreateOptions : CommonOptions
19+
{
20+
[Option('d', "dir", Required = true, HelpText = "The directory to create from.")]
21+
public string Dir { get; set; } = string.Empty;
22+
23+
[Option('r', "recursive", Required = false, HelpText = "Recursive create from Directory.")]
24+
public bool Recursive { get; set; }
25+
}
26+
27+
[Verb("extract", HelpText = "Extract specific file from the .eivp Pack to a directory.")]
28+
public class ExtractOptions : CommonOptions
29+
{
30+
[Option('d', "dir", Required = true, HelpText = "The directory to extract from.")]
31+
public string Dir { get; set; } = string.Empty;
32+
[Option('p', "path", Required = true, HelpText = "The exact file path to extract.")]
33+
public string Path { get; set; } = string.Empty;
34+
}

EIV_DataPack.Console/Program.cs

Lines changed: 53 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,87 @@
1-
using System.CommandLine;
2-
using System.CommandLine.Parsing;
1+
using CommandLine;
32

43
namespace EIV_DataPack.ConsoleApp;
54

65
internal class Program
76
{
87
static void Main(string[] args)
98
{
10-
#region options
11-
var fileOption = new Option<FileInfo>(
12-
name: "--file",
13-
description: "The file to to manipulate.");
14-
15-
var dirOption = new Option<DirectoryInfo>(
16-
name: "--dir",
17-
description: "The directory to create from.");
18-
19-
var recursiveOption = new Option<bool>(
20-
name: "--recursive",
21-
description: "Recursive create from Directory.");
22-
23-
var extractdirOption = new Option<DirectoryInfo>(
24-
name: "--dir",
25-
description: "The directory to extract to.");
26-
27-
var exactFile = new Option<string?>(
28-
name: "--path",
29-
description: "The exact file path to extract.");
30-
31-
#endregion
32-
#region commands
33-
var listCommand = new Command("list", "List all files from the .eivp file")
34-
{
35-
fileOption
36-
};
37-
listCommand.SetHandler(ListFiles, fileOption);
38-
39-
var createCommand = new Command("create", "Create .eivp file from the directory")
40-
{
41-
fileOption,
42-
dirOption,
43-
recursiveOption
44-
};
45-
createCommand.SetHandler(CreateEIVP, fileOption, dirOption, recursiveOption);
46-
47-
var extractCommand = new Command("extract", "Extract specific file from the .eivp Pack to a directory")
48-
{
49-
fileOption,
50-
extractdirOption,
51-
exactFile
52-
};
53-
extractCommand.SetHandler(ExtractSpecific, fileOption, extractdirOption, exactFile);
54-
55-
#endregion
56-
57-
var rootCommand = new RootCommand("EIV DataPack file manipulator");
58-
rootCommand.AddCommand(listCommand);
59-
rootCommand.AddCommand(createCommand);
60-
rootCommand.AddCommand(extractCommand);
61-
rootCommand.Invoke(args);
9+
bool ret = Parser.Default.ParseArguments<ListOptions, CreateOptions, ExtractOptions, FileVersionOption>(args)
10+
.MapResult(
11+
(ListOptions opts) => ListFiles(opts.File),
12+
(CreateOptions opts) => CreateEIVP(opts.File, opts.Dir, opts.Recursive),
13+
(ExtractOptions opts) => ExtractSpecific(opts.File, opts.Dir, opts.Path),
14+
(FileVersionOption opts) => ShowVersion(opts.File),
15+
errs => false);
16+
Console.WriteLine(ret);
6217
}
6318

64-
static void ListFiles(FileInfo fileInfo)
19+
static bool ShowVersion(string FileName)
6520
{
66-
if (fileInfo.Exists)
21+
if (!File.Exists(FileName))
6722
{
68-
var datapackCreator = DatapackCreator.Read(fileInfo.FullName);
69-
var reader = datapackCreator.GetReader();
70-
if (reader == null)
71-
return;
72-
reader.ReadFileNames(false);
73-
reader.Pack.FileNames.ForEach(Console.WriteLine);
23+
Console.WriteLine("File not Exists!");
24+
return false;
7425
}
75-
else
26+
var datapackCreator = DatapackManager.Read(FileName);
27+
var reader = datapackCreator.GetReader();
28+
if (reader == null)
29+
return false;
30+
Console.WriteLine(reader.Pack.Version);
31+
return true;
32+
}
33+
34+
static bool ListFiles(string FileName)
35+
{
36+
if (!File.Exists(FileName))
7637
{
7738
Console.WriteLine("File not Exists!");
39+
return false;
7840
}
41+
var datapackCreator = DatapackManager.Read(FileName);
42+
var reader = datapackCreator.GetReader();
43+
if (reader == null)
44+
return false;
45+
reader.ReadFileNames();
46+
foreach (string item in reader.Pack.FileNames)
47+
Console.WriteLine(item);
48+
return true;
7949
}
8050

81-
static void CreateEIVP(FileInfo fileInfo, DirectoryInfo directory, bool rec)
51+
static bool CreateEIVP(string fileName, string directory, bool rec)
8252
{
83-
var datapack = DatapackCreator.Create(fileInfo.FullName);
53+
var datapack = DatapackManager.Create(fileName);
8454
var writer = datapack.GetWriter();
8555
if (writer == null)
86-
return;
87-
writer.AddDirectory(directory.FullName, rec);
56+
return false;
57+
writer.AddDirectory(directory, rec);
8858
writer.Save();
8959
Console.WriteLine("File Saved!");
60+
return true;
9061
}
9162

92-
static void ExtractAll(FileInfo fileInfo, DirectoryInfo directory)
63+
static bool ExtractSpecific(string fileName, string directory, string? file)
9364
{
94-
if (fileInfo.Exists)
95-
{
96-
var datapackCreator = DatapackCreator.Read(fileInfo.FullName);
97-
var reader = datapackCreator.GetReader();
98-
if (reader == null)
99-
return;
100-
reader.ReadFileNames(false);
101-
102-
}
103-
else
65+
if (!File.Exists(fileName))
10466
{
10567
Console.WriteLine("File not Exists!");
68+
return false;
10669
}
107-
}
108-
static void ExtractSpecific(FileInfo fileInfo, DirectoryInfo directory, string? file)
109-
{
110-
if (fileInfo.Exists)
70+
var datapackCreator = DatapackManager.Read(fileName);
71+
var reader = datapackCreator.GetReader();
72+
if (reader == null)
73+
return false;
74+
if (file == null)
11175
{
112-
var datapackCreator = DatapackCreator.Read(fileInfo.FullName);
113-
var reader = datapackCreator.GetReader();
114-
if (reader == null)
115-
return;
116-
reader.ReadFileNames(false);
117-
if (file == null)
118-
{
119-
reader.Pack.FileNames.ForEach(x => reader.ExportFile(x, Path.Combine(directory.FullName, x)));
120-
return;
121-
}
122-
if (!reader.Pack.FileNames.Contains(file))
123-
{
124-
Console.WriteLine("File to extract is not exists inside the pack!");
125-
return;
126-
}
127-
reader.ExportFile(file, Path.Combine(directory.FullName, file));
76+
reader.Pack.FileNames.ToList().ForEach(x => reader.ExportFile(x, Path.Combine(directory, x)));
77+
return false;
12878
}
129-
else
79+
if (!reader.Pack.FileNames.Contains(file))
13080
{
131-
Console.WriteLine("File not Exists!");
81+
Console.WriteLine("File to extract is not exists inside the pack!");
82+
return false;
13283
}
84+
reader.ExportFile(file, Path.Combine(directory, file));
85+
return true;
13386
}
13487
}

readme.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
extras things will be here. example
1+
extras things will be here. example
2+
3+
#
4+
5+
EIV_DataPack.ConsoleApp.exe create --dir G:\GODOT\EIV\EIV_Core\Json --file EIV_Core.eivp --recursive true
6+
7+
EIV_DataPack.ConsoleApp.exe list --file EIV_Core.eivp

0 commit comments

Comments
 (0)