Skip to content

Commit

Permalink
implemented the DriveMap*-functions (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown6656 committed Mar 22, 2021
1 parent 570e51c commit 31a3e1e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
16 changes: 8 additions & 8 deletions new/AutoItInterpreter/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

//////////////////////////////////////////////////////////////////////////
// Auto-generated 2021-03-22 22:54:08.537 //
// Auto-generated 2021-03-22 23:37:37.791 //
// ANY CHANGES TO THIS DOCUMENT WILL BE LOST UPON RE-GENERATION //
//////////////////////////////////////////////////////////////////////////

using System.Reflection;
using System;

[assembly: AssemblyVersion("0.8.1882.7557")]
[assembly: AssemblyFileVersion("0.8.1882.7557")]
[assembly: AssemblyInformationalVersion("v.0.8.1882.7557, commit: e6ce438d6474307aa98cb81ebfa7288c0394ac1a")]
[assembly: AssemblyVersion("0.8.1883.7557")]
[assembly: AssemblyFileVersion("0.8.1883.7557")]
[assembly: AssemblyInformationalVersion("v.0.8.1883.7557, commit: 570e51c8eb45aedc5971f33747ea94cf7d2b97a1")]
[assembly: AssemblyCompany("Unknown6656")]
[assembly: AssemblyCopyright("Copyright © 2018 - 2021, Unknown6656")]
[assembly: AssemblyProduct("AutoIt-Interpreter by Unknown6656")]
Expand All @@ -35,11 +35,11 @@ public static class __module__
/// <summary>
/// The interpreter's current version.
/// </summary>
public static Version? InterpreterVersion { get; } = Version.Parse("0.8.1882.7557");
public static Version? InterpreterVersion { get; } = Version.Parse("0.8.1883.7557");
/// <summary>
/// The Git hash associated with the current build.
/// </summary>
public const string GitHash = "e6ce438d6474307aa98cb81ebfa7288c0394ac1a";
public const string GitHash = "570e51c8eb45aedc5971f33747ea94cf7d2b97a1";
/// <summary>
/// The name of the GitHub repository associated with <see cref="RepositoryURL"/>.
/// </summary>
Expand All @@ -49,7 +49,7 @@ public static class __module__
/// </summary>
public const string RepositoryURL = "https://github.com/Unknown6656/AutoIt-Interpreter";
/// <summary>
/// The date and time of the current build (2021-03-22 22:54:08.537).
/// The date and time of the current build (2021-03-22 23:37:37.791).
/// </summary>
public static DateTime DateBuilt { get; } = DateTime.FromFileTimeUtc(0x01d71f65e2a58a60L);
public static DateTime DateBuilt { get; } = DateTime.FromFileTimeUtc(0x01d71f6bf5e21787L);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Unknown6656.AutoIt3.CLI;
using Unknown6656.Common;
using Unknown6656.IO;
using Unknown6656.Mathematics;

namespace Unknown6656.AutoIt3.Extensibility.Plugins.Au3Framework
{
Expand All @@ -34,6 +35,8 @@ public sealed class FrameworkFunctions
{
private static readonly Regex REGEX_WS = new(@"[\0\x09-\x0d\x20]{2,}", RegexOptions.Compiled);
private static readonly Regex REGEX_RUN = new(@"^(?<file>""[^""]*""|[^""]+)(\s+(?<args>.*))?$", RegexOptions.Compiled);
private static readonly Regex REGEX_DRIVE_ADD = new(@"Drive (?<letter>.:) is now connected to .*The command completed successfully\.", RegexOptions.Compiled | RegexOptions.Singleline);
private static readonly Regex REGEX_DRIVE_GET = new(@"Remote name\s+(?<target>.+)", RegexOptions.Compiled);


public FrameworkFunctions(Interpreter interpreter)
Expand Down Expand Up @@ -104,6 +107,9 @@ public FrameworkFunctions(Interpreter interpreter)
// RegisterFunction(nameof(DllStructGetPtr), , DllStructGetPtr);
// RegisterFunction(nameof(DllStructGetSize), , DllStructGetSize);
// RegisterFunction(nameof(DllStructSetData), , DllStructSetData);
RegisterFunction(nameof(DriveMapAdd), 2, 5, DriveMapAdd, OS.Windows);
RegisterFunction(nameof(DriveMapDel), 1, DriveMapDel, OS.Windows);
RegisterFunction(nameof(DriveMapGet), 1, DriveMapGet, OS.Windows);
RegisterFunction(nameof(DriveGetDrive), 1, DriveGetDrive);
RegisterFunction(nameof(DriveGetFileSystem), 1, DriveGetFileSystem);
RegisterFunction(nameof(DriveGetLabel), 1, DriveGetLabel);
Expand Down Expand Up @@ -945,6 +951,40 @@ internal static FunctionReturnValue DriveStatus(CallFrame frame, Variant[] args)
return Variant.FromString("INVALID");
}

internal static FunctionReturnValue DriveMapAdd(CallFrame frame, Variant[] args)
{
int flags = (int)args[2];
string user = args[3].ToString();
string pass = args[4].ToString();
string cmd = $"net use \"{args[0]}\" \"{args[1]}\"";

if (flags.HasFlag(1))
cmd += " /persistent:Yes";

if (flags.HasFlag(8))
cmd += $" /user:{user} \"{pass}\"";

(string output, int code) = NativeInterop.Exec(cmd);
bool any = args[0].ToString() == "*";

if (any && output.Match(REGEX_DRIVE_ADD, out Match match))
return (Variant)match.Groups["letter"].Value;
else if (any)
return FunctionReturnValue.Error("", code, code);
else
return FunctionReturnValue.Error(code == 0, code, code);
}

internal static FunctionReturnValue DriveMapDel(CallFrame frame, Variant[] args) => (Variant)NativeInterop.Exec($"net use /D \"{args[0]}\"").code;

internal static FunctionReturnValue DriveMapGet(CallFrame frame, Variant[] args)
{
if (NativeInterop.Exec($"net use \"{args[0]}\"").stdout.Match(REGEX_DRIVE_GET, out Match match))
return (Variant)match.Groups["target"].Value;
else
return FunctionReturnValue.Error(Variant.EmptyString, 1, 0);
}

#endregion
#region E...

Expand Down
4 changes: 2 additions & 2 deletions new/AutoItInterpreter/version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
0.8.1882.7557
e6ce438d6474307aa98cb81ebfa7288c0394ac1a
0.8.1883.7557
570e51c8eb45aedc5971f33747ea94cf7d2b97a1

0 comments on commit 31a3e1e

Please sign in to comment.