-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a61bc50
commit 5a0688b
Showing
13 changed files
with
275 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace NyaFs.Processor.Scripting.Commands.Fs.Interactive | ||
{ | ||
class Cd : ScriptStepGenerator | ||
{ | ||
public Cd() : base("cd") | ||
{ | ||
AddConfig(new ScriptArgsConfig(0, new ScriptArgsParam[] { new Params.FsPathScriptArgsParam() })); | ||
} | ||
public override ScriptStep Get(ScriptArgs Args) | ||
{ | ||
return new CdScriptStep(Args.RawArgs[0]); | ||
} | ||
|
||
public class CdScriptStep : ScriptStep | ||
{ | ||
string Path; | ||
|
||
public CdScriptStep(string Path) : base("cd") | ||
{ | ||
this.Path = Path; | ||
} | ||
|
||
private string CombinePath(string Base, string Name) | ||
{ | ||
if ((Base == "/") || (Base == ".")) return Name; | ||
|
||
return Base + "/" + Name; | ||
} | ||
|
||
public override ScriptStepResult Exec(ImageProcessor Processor) | ||
{ | ||
var Fs = Processor.GetFs(); | ||
if ((Fs == null) || !Fs.Loaded) | ||
return new ScriptStepResult(ScriptStepStatus.Error, "Filesystem not loaded"); | ||
else | ||
{ | ||
if(Path.Length == 0) | ||
return new ScriptStepResult(ScriptStepStatus.Error, "Specify path!"); | ||
|
||
if (Path == ".") | ||
return new ScriptStepResult(ScriptStepStatus.Ok, Processor.ActivePath); | ||
|
||
var Item = Helper.FsHelper.GetItem(Fs, Processor.ActivePath, Path); | ||
|
||
if(Item != null) | ||
{ | ||
Processor.ActivePath = "/" + Item.Filename; | ||
return new ScriptStepResult(ScriptStepStatus.Error, $"Active directory is changed to {Processor.ActivePath}."); | ||
} | ||
else | ||
return new ScriptStepResult(ScriptStepStatus.Error, "Specified path is not found."); | ||
} | ||
} | ||
} | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
NyaFs/Processor/Scripting/Commands/Fs/Interactive/Ls.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace NyaFs.Processor.Scripting.Commands.Fs.Interactive | ||
{ | ||
class Ls : ScriptStepGenerator | ||
{ | ||
public Ls() : base("ls") | ||
{ | ||
AddConfig(new ScriptArgsConfig(0, new ScriptArgsParam[] { })); | ||
AddConfig(new ScriptArgsConfig(1, new ScriptArgsParam[] { new Params.FsPathScriptArgsParam() })); | ||
} | ||
public override ScriptStep Get(ScriptArgs Args) | ||
{ | ||
if(Args.ArgConfig == 0) | ||
return new LsScriptStep(); | ||
else | ||
return new LsScriptStep(Args.RawArgs[0]); | ||
} | ||
|
||
public class LsScriptStep : ScriptStep | ||
{ | ||
string Path = null; | ||
|
||
public LsScriptStep() : base("ls") | ||
{ | ||
|
||
} | ||
|
||
public LsScriptStep(string Path) : base("ls") | ||
{ | ||
this.Path = Path; | ||
} | ||
|
||
private ImageFormat.Elements.Fs.Items.Dir GetTarget(ImageFormat.Elements.Fs.Filesystem Fs, string Active) | ||
{ | ||
if (Path == null) | ||
{ | ||
try | ||
{ | ||
return Fs.GetDirectory(Active); | ||
} | ||
catch(Exception E) | ||
{ | ||
return null; | ||
} | ||
} | ||
else | ||
{ | ||
return Helper.FsHelper.GetItem(Fs, Active, Path) as ImageFormat.Elements.Fs.Items.Dir; | ||
} | ||
} | ||
|
||
public override ScriptStepResult Exec(ImageProcessor Processor) | ||
{ | ||
var Fs = Processor.GetFs(); | ||
if ((Fs == null) || !Fs.Loaded) | ||
return new ScriptStepResult(ScriptStepStatus.Error, "Filesystem not loaded"); | ||
else | ||
{ | ||
var Target = GetTarget(Fs, Processor.ActivePath); | ||
|
||
if (Target == null) | ||
return new ScriptStepResult(ScriptStepStatus.Error, "Target directory is not found!"); | ||
|
||
foreach (var I in Target.Items) | ||
{ | ||
Log.Write(0, FormatItem(I)); | ||
} | ||
|
||
return new ScriptStepResult(ScriptStepStatus.Ok, null); | ||
} | ||
} | ||
|
||
private string FormatItem(ImageFormat.Elements.Fs.FilesystemItem Item) | ||
{ | ||
var Mode = $"{GetItemType(Item)}{ConvertModeToString(Item.Mode)}"; | ||
var User = $"{Item.User}".PadLeft(5); | ||
var Group = $"{Item.Group}".PadLeft(5); | ||
|
||
var Size = $"{Item.Size}".PadLeft(12); | ||
|
||
var Name = (Item.ItemType == ImageFormat.Types.FilesystemItemType.SymLink) ? $"{Item.ShortFilename} -> {(Item as ImageFormat.Elements.Fs.Items.SymLink).Target}" : Item.ShortFilename; | ||
|
||
return $"{Mode} {User} {Group} {Size} {Name}"; | ||
} | ||
|
||
private string GetItemType(ImageFormat.Elements.Fs.FilesystemItem Item) | ||
{ | ||
switch(Item.ItemType) | ||
{ | ||
case ImageFormat.Types.FilesystemItemType.File: return "-"; | ||
case ImageFormat.Types.FilesystemItemType.Dir: return "d"; | ||
case ImageFormat.Types.FilesystemItemType.SymLink: return "l"; | ||
case ImageFormat.Types.FilesystemItemType.Node: return "c"; | ||
case ImageFormat.Types.FilesystemItemType.Block: return "b"; | ||
case ImageFormat.Types.FilesystemItemType.Fifo: return "f"; | ||
default: return "?"; | ||
} | ||
} | ||
public static string ConvertModeToString(UInt32 Mode) | ||
{ | ||
var Res = ""; | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
UInt32 Part = (Mode >> (2 - i) * 4) & 0x7; | ||
|
||
Res += ((Part & 0x04) != 0) ? "r" : "-"; | ||
Res += ((Part & 0x02) != 0) ? "w" : "-"; | ||
Res += ((Part & 0x01) != 0) ? ((((Mode >> 12 >> (2 - i)) & 0x1) != 1) ? "x" : "s") : "-"; | ||
} | ||
return Res; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace NyaFs.Processor.Scripting.Commands.Fs.Interactive | ||
{ | ||
class Pwd : ScriptStepGenerator | ||
{ | ||
public Pwd() : base("pwd") | ||
{ | ||
AddConfig(new ScriptArgsConfig(0, new ScriptArgsParam[] { })); | ||
} | ||
public override ScriptStep Get(ScriptArgs Args) | ||
{ | ||
return new PwdScriptStep(); | ||
} | ||
|
||
public class PwdScriptStep : ScriptStep | ||
{ | ||
public PwdScriptStep() : base("pwd") | ||
{ | ||
|
||
} | ||
|
||
public override ScriptStepResult Exec(ImageProcessor Processor) | ||
{ | ||
var Fs = Processor.GetFs(); | ||
if ((Fs == null) || !Fs.Loaded) | ||
return new ScriptStepResult(ScriptStepStatus.Error, "Filesystem not loaded"); | ||
else | ||
return new ScriptStepResult(ScriptStepStatus.Ok, Processor.ActivePath); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.