Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit d0dbeca

Browse files
committed
Remade architecture
1 parent 352ac55 commit d0dbeca

20 files changed

Lines changed: 468 additions & 199 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Thumbs.db
22
*.obj
33
*.exe
4+
*.dll
45
*.pdb
56
*.user
67
*.aps

Deodexer/Commands/Command.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Collections.Generic;
2+
using Deodexer.PathPlaceholders;
3+
4+
namespace Deodexer.Commands
5+
{
6+
abstract class Command
7+
{
8+
public string description = "Description is not available";
9+
public string detailedDescription = null;
10+
abstract public void exec(List<string> args = null);
11+
public List<IPathPlaceholder> placeholders=new List<IPathPlaceholder>();
12+
public IPathPlaceholder defaultPlaceholder;
13+
14+
public void preprocessArguments(List<string> args){
15+
List<string> nm;
16+
if(args.Count==0 && defaultPlaceholder!=null)
17+
args.AddRange(defaultPlaceholder.exec());
18+
foreach (var placeholder in placeholders) {
19+
for (int i = 0; i < args.Count; i++) {
20+
nm = placeholder.expand(args[i]);
21+
if (nm != null) {
22+
args.RemoveAt(i);
23+
args.InsertRange(i, nm);
24+
}
25+
}
26+
}
27+
}
28+
}
29+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Deodexer.Commands
5+
{
6+
class CreditsCommand : Command
7+
{
8+
public CreditsCommand() {
9+
description = "Shows credits";
10+
}
11+
12+
override public void exec(List<string> args = null) {
13+
Console.WriteLine();
14+
Console.WriteLine("Deodexer");
15+
Console.WriteLine("Copyleft by KOLANICH, 2013");
16+
Console.WriteLine(@"The license is Apache License. More info in https://github.com/KOLANICH/Deodexer/blob/master/LICENSE and http://tldrlegal.com/license/apache-license-2.0-%28apache-2.0%29");
17+
Console.WriteLine(@"More info on Github: https://github.com/KOLANICH/Deodexer/");
18+
}
19+
}
20+
}

Deodexer/Commands/DeodexCommand.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
5+
namespace Deodexer.Commands
6+
{
7+
class DeodexCommand : FileProcessingComand
8+
{
9+
private Deodexer deodexer;
10+
protected override string fileTypes {
11+
get { return "Android Java Packages|*.apk;*.jar|All Files|*.*"; }
12+
}
13+
14+
protected override string title{
15+
get { return "Select files to be deodexed"; }
16+
}
17+
18+
public DeodexCommand(Deodexer deodexer){
19+
description = "Deodexes a apk/jar file and aligns it";
20+
detailedDescription = "usage: deodex file1 file2 file3 file4 etc" + Environment.NewLine;
21+
this.deodexer = deodexer;
22+
}
23+
24+
public override void exec(List<string> fileNames) {
25+
foreach (string fn in fileNames)
26+
processFileOrDir(fn);
27+
}
28+
29+
protected override bool filter(string filename) {
30+
var ext = Path.GetExtension(filename);
31+
return (ext == ".jar" || ext == ".apk");
32+
}
33+
34+
protected override void processFile(string filename) {
35+
deodexer.deodex(filename);
36+
}
37+
}
38+
39+
}

Deodexer/Commands/EchoCommand.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Deodexer.PathPlaceholders;
4+
5+
namespace Deodexer.Commands
6+
{
7+
class EchoCommand:Command
8+
{
9+
10+
public EchoCommand(){
11+
description = "Used to test different placeholders";
12+
placeholders.Add(new FileDialogPlaceholder());
13+
placeholders.Add(new FolderDialogPlaceholder());
14+
}
15+
16+
override public void exec(List<string> cmds){
17+
foreach (var cmd in cmds) {
18+
Console.Write(cmd);
19+
Console.Write('\t');
20+
}
21+
Console.WriteLine();
22+
}
23+
}
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Deodexer.Commands
5+
{
6+
class ExitAppCommand : Command
7+
{
8+
public ExitAppCommand() {
9+
description = "exits application";
10+
detailedDescription = "exits this application";
11+
}
12+
override public void exec(List<string> args = null) {
13+
Environment.Exit(0);
14+
}
15+
}
16+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.IO;
3+
using Deodexer.PathPlaceholders;
4+
5+
namespace Deodexer.Commands
6+
{
7+
abstract class FileProcessingComand : FolderProcessingCommand
8+
{
9+
protected abstract string fileTypes {get;}
10+
11+
protected FileProcessingComand() {
12+
description = "Used for file operations";
13+
detailedDescription = "fileN - path of a file or a folder or one of the constants:" + Environment.NewLine +
14+
"\t%ASK% - shows a dialog for picking file" + Environment.NewLine +
15+
"\t? - alias for ask" + Environment.NewLine;
16+
defaultPlaceholder = new FileDialogPlaceholder(fileTypes, title);
17+
placeholders.Add(defaultPlaceholder);
18+
}
19+
20+
protected void processFileOrDir(string fn) {
21+
if (Directory.Exists(fn)) {
22+
var dirInfo = new DirectoryInfo(fn);
23+
var dirs = dirInfo.GetDirectories();
24+
var files = dirInfo.GetFiles();
25+
foreach (var file in files) {
26+
if(filter(file.FullName))
27+
processFileOrDir(file.FullName);
28+
}
29+
foreach (var dir in dirs)
30+
processFileOrDir(dir.FullName);
31+
} else if (File.Exists(fn)) {
32+
processFile(Path.GetFullPath(fn));
33+
} else {
34+
var prevCol = Console.ForegroundColor;
35+
Console.ForegroundColor = ConsoleColor.Red;
36+
Console.WriteLine("File " + fn + " doesn't exist!");
37+
Console.ForegroundColor = prevCol;
38+
}
39+
}
40+
41+
protected virtual bool filter(string filename) {
42+
return true;
43+
}
44+
45+
protected virtual void processFile(string filename){
46+
}
47+
}
48+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using Deodexer.PathPlaceholders;
3+
4+
namespace Deodexer.Commands
5+
{
6+
abstract class FolderProcessingCommand : Command, IDisposable
7+
{
8+
protected abstract string title { get; }
9+
10+
protected FolderProcessingCommand() {
11+
description = "Used for folder operations";
12+
detailedDescription = "";
13+
placeholders.Add(new FolderDialogPlaceholder(title));
14+
}
15+
public void Dispose() {
16+
foreach (var placeholder in placeholders) {
17+
placeholder.Dispose();
18+
}
19+
}
20+
}
21+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
5+
namespace Deodexer.Commands
6+
{
7+
class FrameworkCommand : FolderProcessingCommand
8+
{
9+
private Deodexer deodexer;
10+
public FrameworkCommand(Deodexer deodexer) {
11+
description = "Used to set framework directory.";
12+
this.deodexer = deodexer;
13+
}
14+
15+
public override void exec(List<string> dirs) {
16+
string dir = dirs.Count == 0 ? Deodexer.defaultFrameworkDir : dirs[0];
17+
if (Directory.Exists(dir))
18+
deodexer.frameworkDir = dir;
19+
else {
20+
var prevCol = Console.ForegroundColor;
21+
Console.ForegroundColor = ConsoleColor.Red;
22+
Console.WriteLine("Directory doesn't exist");
23+
Console.ForegroundColor = prevCol;
24+
}
25+
}
26+
27+
protected override string title {
28+
get { return "Select the folder you want to set as framework folder"; }
29+
}
30+
}
31+
}

Deodexer/Commands/HelpCommand.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Deodexer.Commands
5+
{
6+
class HelpCommand : Command
7+
{
8+
private Menu menu;
9+
10+
public HelpCommand(Menu menu) {
11+
this.menu = menu;
12+
description = "Shows this help";
13+
}
14+
15+
override public void exec(List<string> cmds = null) {
16+
if (cmds.Count==0) {
17+
foreach (var cmd in menu.commands) {
18+
Console.WriteLine(cmd.Key + " :" + Environment.NewLine + "\t" + cmd.Value.description.Replace(Environment.NewLine, Environment.NewLine + "\t"));
19+
}
20+
} else {
21+
foreach (var cmd in cmds)
22+
if (menu.commands.ContainsKey(cmd)) {
23+
Console.ForegroundColor = ConsoleColor.Blue;
24+
Console.WriteLine(cmd +
25+
Environment.NewLine + menu.commands[cmd].description +
26+
(
27+
menu.commands[cmd].detailedDescription != null
28+
? (Environment.NewLine + menu.commands[cmd].detailedDescription)
29+
: ""
30+
)
31+
);
32+
} else {
33+
Console.ForegroundColor = ConsoleColor.DarkRed;
34+
Console.WriteLine("Command " + cmd + "is not found!!!");
35+
}
36+
}
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)