Added folder / file Manager to the Client
This commit is contained in:
@@ -38,12 +38,12 @@ namespace Active_Client.Browser_Tools
|
||||
|
||||
private static readonly string[] _validExtensions = {".json", ".rcp", ".tpl" };
|
||||
//private static readonly string[] _validExtensions = { "", ".txt", ".cnc", ".cn", ".cno", ".ini", ".mpf", ".spf", ".tap", ".anc", ".iso" };
|
||||
private static readonly string[] _validImages = { ".jpg", ".jpeg", ".png" };
|
||||
private static readonly string[] _validImages = { ".jpg", ".jpeg", ".png", ".svg" };
|
||||
private static string jobPath = "";
|
||||
private static Dictionary<string, IntPtr> _editorOpened = new Dictionary<string, IntPtr>();
|
||||
private static EditorVar _currentEditorObject = new EditorVar();
|
||||
public static string RECENT_FOLDER_KEY = "RECENT";
|
||||
private const string THERMO_RECIPE_PATH = @"C:\CMS\Recipes";
|
||||
private const string THERMO_RECIPE_PATH = @"C:\CMS\Recipe";
|
||||
|
||||
public static FileSystemWatcher watcher = null;
|
||||
public static DateTime _lastTimeFileWatcherEventRaised = DateTime.Now;
|
||||
@@ -80,6 +80,11 @@ namespace Active_Client.Browser_Tools
|
||||
AddFunction("getFileList").Execute += getFileList;
|
||||
AddFunction("getProgramInfo").Execute += getProgramInfo;
|
||||
AddFunction("editProgram").Execute += editProgram;
|
||||
AddFunction("deleteFile").Execute += deleteFile;
|
||||
AddFunction("deleteFolder").Execute += deleteFolder;
|
||||
AddFunction("createFolder").Execute += createFolder;
|
||||
|
||||
|
||||
|
||||
AddFunction("uploadAndActivateProgram").Execute += uploadAndActivateProgram;
|
||||
AddFunction("uploadAndAddToQueue").Execute += uploadAndAddToQueue;
|
||||
@@ -360,6 +365,7 @@ namespace Active_Client.Browser_Tools
|
||||
List<Drive> drivelist = new List<Drive>();
|
||||
|
||||
// USB & HD Drives
|
||||
/*
|
||||
foreach (var drive in DriveInfo.GetDrives())
|
||||
{
|
||||
if (drive.IsReady)
|
||||
@@ -376,7 +382,7 @@ namespace Active_Client.Browser_Tools
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Desktop folder
|
||||
drivelist.Add(new Drive()
|
||||
{
|
||||
@@ -384,6 +390,7 @@ namespace Active_Client.Browser_Tools
|
||||
Path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\",
|
||||
Type = "SPFO"
|
||||
});
|
||||
*/
|
||||
|
||||
if (Directory.Exists(THERMO_RECIPE_PATH))
|
||||
{
|
||||
@@ -394,7 +401,7 @@ namespace Active_Client.Browser_Tools
|
||||
Type = "SPFO"
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
try
|
||||
{
|
||||
// Network Folders
|
||||
@@ -416,7 +423,7 @@ namespace Active_Client.Browser_Tools
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(drivelist));
|
||||
}
|
||||
@@ -485,6 +492,85 @@ namespace Active_Client.Browser_Tools
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(filelist));
|
||||
}
|
||||
|
||||
public void deleteFile(object sender, CfrV8HandlerExecuteEventArgs e)
|
||||
{
|
||||
if (e.Arguments.Count() == 0)
|
||||
{
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("error_arguments_not_ok")));
|
||||
return;
|
||||
}
|
||||
|
||||
// Get path
|
||||
string p = e.Arguments[0].StringValue;
|
||||
FileAttributes attr = File.GetAttributes(p);
|
||||
if (!File.Exists(p) || attr.HasFlag(FileAttributes.Directory))
|
||||
{
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("file_not_found")));
|
||||
return;
|
||||
}
|
||||
if (attr.HasFlag(FileAttributes.ReadOnly))
|
||||
{
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("file_not_editable")));
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
File.Delete(p);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("cannot_delete_file")));
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteFolder(object sender, CfrV8HandlerExecuteEventArgs e)
|
||||
{
|
||||
if (e.Arguments.Count() == 0)
|
||||
{
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("error_arguments_not_ok")));
|
||||
return;
|
||||
}
|
||||
|
||||
// Get path
|
||||
string p = e.Arguments[0].StringValue;
|
||||
FileAttributes attr = File.GetAttributes(p);
|
||||
if (!Directory.Exists(p) || !attr.HasFlag(FileAttributes.Directory))
|
||||
{
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("directory_not_found")));
|
||||
return;
|
||||
}
|
||||
if (attr.HasFlag(FileAttributes.ReadOnly))
|
||||
{
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("directory_not_editable")));
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
Directory.Delete(p,true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("cannot_delete_directory")));
|
||||
}
|
||||
}
|
||||
|
||||
public void createFolder(object sender, CfrV8HandlerExecuteEventArgs e)
|
||||
{
|
||||
if (e.Arguments.Count() == 0)
|
||||
{
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("error_arguments_not_ok")));
|
||||
return;
|
||||
}
|
||||
string path = e.Arguments[0].StringValue;
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
e.SetReturnValue(JsonConvert.SerializeObject(new ErrorContainer("cannot_delete_directory")));
|
||||
}
|
||||
}
|
||||
// Upload and activate the program
|
||||
public async void uploadAndActivateProgram(object sender, CfrV8HandlerExecuteEventArgs e)
|
||||
{
|
||||
@@ -671,8 +757,7 @@ namespace Active_Client.Browser_Tools
|
||||
// Read info of a file
|
||||
public void getProgramInfo(object sender, CfrV8HandlerExecuteEventArgs e)
|
||||
{
|
||||
string line, imagePath, imageDirectory;
|
||||
int counter = 0;
|
||||
string imagePath, imageDirectory;
|
||||
|
||||
if (e.Arguments.Count() == 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user