public bool RMFile(IGC_URL url, IGC_User user) { if (FileExists(url.fullpath)) { IGC_File file = GetFile(url.fullpath); if (!CanAccessFile(file, user)) { return(false); } else { RemoveFileActions(file); if (virtualSystem.networkReady) { GetComponent <NetworkView>().RPC("RemoveFileRPC", RPCMode.Others, url.fullpath); } return(true); } } else { return(false); } }
private string FormatLSString(IGC_URL[] urls, bool asList) { if (urls.Length == 0) { return(""); } string[] list = new string[urls.Length]; for (int i = 0; i < urls.Length; i++) { if (asList) { IGC_File file = fs.GetFile(urls[i].fullpath); string uniformLengthOwnerName = file.owner.name.PadRight(9, ' ').Substring(0, 9); list[i] = (file.protectedFile ? "y" : "n") + " - " + uniformLengthOwnerName + " - " + file.accessGroups.Count + "/" + file.editGroups.Count + " - " + (file.isDir ? "d" : "f") + " - " + file.name; } else { list[i] = urls[i].filename; } } string columns = urls.Length + " items\nprotected | owner | groups r/w | type | name\n"; return((asList ? columns : "") + string.Join((asList ? "\n" : " "), list)); }
private string cd(IGC_URL url) { IGC_File file = fs.GetFile(url.fullpath); if (file != null) { if (file.isDir) { if (!fs.CanAccessFile(file, issuer)) { return("you do not have permission to enter this directory"); } issuer.cwd = file.path; if (virtualSystem.networkReady) { virtualSystem.GetComponent <NetworkView>().RPC("UpdateCWDRPC", RPCMode.Others, issuer.name, file.path); } return(""); } else { return(url.fullpath + " is not a directory"); } } return(url.fullpath + " does not exist"); }
public IGC_File CreateFile(IGC_URL url, IGC_User user, bool isDir) { if (FileExists(url.fullpath)) { return(null); } IGC_File targetDir = GetFile(url.dirpath); if (targetDir != null && targetDir.isDir) { if (!CanAccessFile(targetDir, user)) { return(null); } IGC_File file = CreateFileGameObject(url, user.name, isDir); if (virtualSystem.networkReady) { GetComponent <NetworkView>().RPC("CreateFileRPC", RPCMode.Others, url.fullpath, user.name, isDir); } return(file); } else { return(null); } }
public override string command_function() { if (argv.Length < 2) { return(malformed_error + "\n" + usage); } IGC_FileSystem fs = virtualSystem.fileSystem; IGC_URL url = fs.ParseURL(argv [1], issuer.cwd); if (!fs.FileExists(url.fullpath)) { IGC_File file = fs.CreateFile(url, issuer, false); if (file != null) { return("file " + file.path + " created successfully"); } else { return("error: insufficient privilages or broken path"); } } return(url.fullpath + " already exists"); }
public override string command_function() { IGC_FileSystem fs = virtualSystem.fileSystem; if (argv.Length > 1) { IGC_URL url = fs.ParseURL(argv[1], issuer.cwd); IGC_File file = fs.GetFile(url.fullpath); if (file != null) { if (!fs.CanAccessFile(file, issuer)) { return("You do not have permission to view this file"); } return(file.data); } else { return("file " + url.fullpath + " does not exist"); } } else { return(malformed_error + "\n" + this.usage); } }
public override string command_function() { if (argv.Length != 2) { return(malformed_error + "\n" + usage); } IGC_FileSystem fs = virtualSystem.fileSystem; IGC_URL url = fs.ParseURL(argv [1], issuer.cwd); IGC_File file = fs.GetFile(url.fullpath); if (file == null) { return(url.fullpath + " does not exits"); } if (!fs.CanEditFile(file, issuer)) { return("you do not have permission to edit this file"); } issuer.terminal.shell.EnterEditMode(file); return(""); }
public override string command_function() { if (argv.Length < 2) { return(malformed_error + "\n" + usage); } IGC_FileSystem fs = virtualSystem.fileSystem; IGC_URL url = fs.ParseURL(argv [1], issuer.cwd); if (!fs.CanAccessFile(fs.GetFile(url.dirpath), issuer)) { return("you do not have permission to create files in that location"); } if (!fs.FileExists(url.fullpath)) { IGC_File dir = fs.CreateFile(url, issuer, true); if (dir != null) { return("directory " + url.fullpath + " created successfully"); } else { return("error: broken path"); } } return(url.fullpath + " already exists"); }
private void RemoveFileActions(IGC_File file) { string fileIndex = file.path; RemoveFolderChildren(file.transform); Destroy(file.gameObject); files.Remove(fileIndex); }
public override string command_function() { if (argv.Length != 3) { return(this.malformed_error + "\n" + this.usage); } IGC_FileSystem fs = virtualSystem.fileSystem; IGC_URL oldURL = fs.ParseURL(argv[1], issuer.cwd), newURL = fs.ParseURL(argv[2], issuer.cwd); if (!fs.FileExists(oldURL.fullpath)) { return("cant move " + argv[1] + " because it doesn't exist"); } Debug.Log("from " + oldURL.fullpath); if (!fs.FileExists(newURL.dirpath)) { return("cant move " + argv[1] + " to " + newURL.dirname + " because that directory does not exist."); } Debug.Log("to " + newURL.dirpath); if (fs.FileExists(newURL.fullpath)) { return("new path " + argv[2] + " already exists - have you added the file name to the path?"); } Debug.Log("to fullpath " + newURL.fullpath); IGC_File file = fs.GetFile(oldURL.fullpath); IGC_File dir = fs.GetFile(newURL.dirpath); if (!fs.CanAccessFile(file, issuer)) { return("you do not have permission to edit " + oldURL.fullpath); } if (!fs.CanAccessFile(dir, issuer)) { return("you do not have permission to access " + newURL.dirname); } if (argv[2] == "SVR-01") { } //if svr get gameobject tagged playerserver - move the file from current gameobject to the playerserver gameobject //new move file method in FS required, one that takes gameobjects - convert this to extract command? fs.MoveFile(oldURL, newURL); if (virtualSystem.networkReady) { fs.GetComponent <NetworkView>().RPC("MoveFileRPC", RPCMode.Others, oldURL.fullpath, newURL.fullpath); } return(oldURL.filename + " changed to " + newURL.fullpath); }
private string SaveActions() { lastEditedFile.data = rawEditString; string output = lastEditedFile.name + " saved"; lastEditedFile = null; rawEditString = ""; return(output); }
private void CreateUserHomeDir(IGC_User user) { IGC_File homeDir = virtualSystem.fileSystem.CreateFile(virtualSystem.fileSystem.ParseURL(user.homedir, user.cwd), systemUser, true); if (homeDir == null) //if it exists, createfile will return null { homeDir = virtualSystem.fileSystem.files["/home/" + user.name]; } homeDir.fileOwner = user.name; }
public void MoveFile(IGC_URL oldURL, IGC_URL newURL) { IGC_File file = GetFile(oldURL.fullpath); files.Remove(oldURL.fullpath); file.path = newURL.fullpath; file.transform.parent = GetFile(newURL.dirpath).transform; file.gameObject.name = newURL.filename; files.Add(newURL.fullpath, file); }
public void GetFilesRecursive(Transform target) { foreach (Transform child in target) { IGC_File f = child.GetComponent <IGC_File> (); if (f != null) { files.Add(f.path, f); } GetFilesRecursive(child); } }
public void CopyFile(IGC_URL target, IGC_URL copy) { IGC_File file = GetFile(target.fullpath); IGC_File dir = GetFile(copy.dirpath); IGC_File newFile = (GameObject.Instantiate(file.gameObject) as GameObject).GetComponent <IGC_File>(); newFile.gameObject.name = copy.filename; newFile.path = copy.fullpath; newFile.transform.parent = dir.transform; newFile.accessGroups = file.accessGroups; newFile.editGroups = file.editGroups; files.Add(copy.fullpath, newFile); }
public override string command_function() { if (argv.Length != 3) { return(this.malformed_error + "\n" + this.usage); } IGC_FileSystem fs = virtualSystem.fileSystem; IGC_URL target = fs.ParseURL(argv[1], issuer.cwd), copy = fs.ParseURL(argv[2], issuer.cwd); if (!fs.FileExists(target.fullpath)) { return("cant copy " + target.fullpath + " because it doesn't exist"); } if (!fs.FileExists(copy.dirpath)) { return("cant copy " + target.filename + " to " + copy.dirname + " because that directory does not exist."); } if (fs.FileExists(copy.fullpath)) { return(copy.fullpath + " already exists"); } IGC_File file = fs.GetFile(target.fullpath); IGC_File dir = fs.GetFile(copy.dirpath); if (!fs.CanAccessFile(file, issuer)) { return("you do not have permission to copy " + target.fullpath); } if (!fs.CanAccessFile(dir, issuer)) { return("you do not have permission to access " + copy.dirname); } fs.CopyFile(target, copy); if (virtualSystem.networkReady) { fs.GetComponent <NetworkView>().RPC("CopyFileRPC", RPCMode.Others, target.fullpath, copy.fullpath); } return(target.filename + " copied to " + copy.fullpath); }
private IGC_File CreateFileGameObject(IGC_URL url, string username, bool isDir) { GameObject go = new GameObject(url.filename); go.transform.parent = url.dirpath == "/" ? rootNode.transform : GetFile(url.dirpath).transform; IGC_File file = go.AddComponent <IGC_File>(); file.fileOwner = username; file.isDir = isDir; files.Add(url.fullpath, file); return(file); }
public override string command_function() { if (argv.Length != 3) { return(this.malformed_error + "\n" + this.usage); } IGC_FileSystem fs = virtualSystem.fileSystem; IGC_URL oldURL = fs.ParseURL(argv[1], issuer.cwd), newURL = fs.ParseURL(argv[2], issuer.cwd); if (!fs.FileExists(oldURL.fullpath)) { return("cant move " + argv[1] + " because it doesn't exist"); } if (!fs.FileExists(newURL.dirpath)) { return("cant move " + argv[1] + " to " + newURL.dirname + " because that directory does not exist."); } if (fs.FileExists(newURL.fullpath)) { return("new path " + argv[2] + " already exists"); } IGC_File file = fs.GetFile(oldURL.fullpath); IGC_File dir = fs.GetFile(newURL.dirpath); if (!fs.CanAccessFile(file, issuer)) { return("you do not have permission to edit " + oldURL.fullpath); } if (!fs.CanAccessFile(dir, issuer)) { return("you do not have permission to access " + newURL.dirname); } fs.MoveFile(oldURL, newURL); if (virtualSystem.networkReady) { fs.GetComponent <NetworkView>().RPC("MoveFileRPC", RPCMode.Others, oldURL.fullpath, newURL.fullpath); } return(oldURL.filename + " changed to " + newURL.fullpath); }
IEnumerator SetupEditMode(IGC_File targetFile) { while (true) { yield return(new WaitForSeconds(0.1f)); break; } lastEditedFile = targetFile; string fname = computer.virtualSystem.fileSystem.ParseURL(targetFile.path, "/").filename; prompt.text = "EDITING " + fname + " | ESCAPE TO EXIT"; rawEditString = targetFile.data; output.text = FormatForEdit(rawEditString); UpdateCursor(); UpdateScreenNetwork(); }
public override string command_function() { if (argv.Length != 2) { return(malformed_error + "\n" + usage); } IGC_FileSystem fs = virtualSystem.fileSystem; IGC_URL url = fs.ParseURL(argv [1], issuer.cwd); IGC_File file = fs.GetFile(url.fullpath); if (file == null) { return("input file does not exist"); } Transform platforms = GameObject.Find("room/platforms").transform; string[] bridgeFormationData = IGC_Utils.SplitString(",", file.data); if (bridgeFormationData.Length != 10) { return("incorrect number of comma seporated numbers in input file. must be 10."); } int i = 0; foreach (string s in bridgeFormationData) { int num = int.Parse(s.Trim()); Transform t = platforms.Find(i.ToString()); t.GetComponent <BridgeSegment>().SetTargetPosition(new Vector3( t.transform.localPosition.x, num, t.transform.localPosition.z )); i++; } return("bridge formation reset"); }
public override string command_function() { if (argv.Length < 2) { return(malformed_error + "\n" + usage); } IGC_FileSystem fs = virtualSystem.fileSystem; IGC_URL url = fs.ParseURL(argv [1], issuer.cwd); IGC_File file = fs.GetFile(url.fullpath); if (file != null) { if (!fs.CanAccessFile(file, issuer)) { return("you do not have permission to delete " + file.path); } if (file.isDir && argv.Length < 3) { return("you must type '-r' after the folder name to delete a folder and all files/folders within"); } if (!file.isDir || (file.isDir && argv[2] == "-r")) { if (fs.RMFile(url, issuer)) { return(url.fullpath + " deleted"); } else { return("system error. could not delete file...?"); } } else { return(malformed_error + usage); } } return(url.fullpath + " does not exist"); }
private string FileInfo() { if (argv.Length != 2) { return(malformed_error + "\nusage: file <filename>"); } IGC_URL url = fs.ParseURL(argv [1], issuer.cwd); IGC_File file = fs.GetFile(url.fullpath); if (file != null) { string output = "TYPE: " + file.type; output += "\nOWNER: " + file.owner.name; output += "\nPROTECTED: " + file.protectedFile; output += "\nREAD GROUPS: " + string.Join(", ", file.ListAccessGroups()); output += "\nWRITE GROUPS: " + string.Join(", ", file.ListEditGroups()); return(output); } return("file " + url.fullpath + " does not exist"); }
public bool CanAccessFile(IGC_File file, IGC_User user) { if (user.isAdmin) { //Debug.Log("admins can access any file. "); return(true); } else { if (file.protectedFile) { //Debug.Log("not admin? if protected, no. "); return(false); } else { if (file.accessGroups.Count == 0) { //Debug.Log("if not protected. if you own it, yes. "); return(true); } else { if (file.accessGroups.Count > 0) { foreach (IGC_UserGroup ag in file.accessGroups) { if (user.groups.Contains(ag)) { //Debug.Log("if not... if you belong to one of its access groups, yes"); return(true); } } } } } } //Debug.Log("FINAL NO"); return(false); }
private string ls(IGC_URL url, bool showHidden, bool asList) { IGC_File file = fs.GetFile(url.fullpath); if (file != null) { if (!fs.CanAccessFile(file, issuer)) { return("you do not have permission to view this directory"); } if (file.isDir) { return(FormatLSString(fs.ListFiles(url, issuer.cwd, showHidden), asList)); } else { return(file.path + " is not a directory"); } } return(url.fullpath + " does not exist"); }
public void ApplyFileGroups() { string filesString = virtualSystem.GetFilesString(virtualSystem.restoreData); string[] filesStringList = IGC_Utils.SplitString("\n", filesString); for (int i = 0; i < filesStringList.Length; i++) { string[] fileString = IGC_Utils.SplitString(":", filesStringList[i]), groups = IGC_Utils.SplitString("~", fileString[7]), editgroups = IGC_Utils.SplitString("~", fileString[8]); IGC_File file = GetFile(fileString[0]); if (file == null) { continue; } //if there are no groups of the file ! exist, go to next if (fileString[7] != "NONE") { foreach (string groupname in groups) { file.accessGroups.Add(virtualSystem.userRegistry.groups[groupname]); } } if (fileString[8] != "NONE") { foreach (string editgroupname in editgroups) { file.editGroups.Add(virtualSystem.userRegistry.groups[editgroupname]); } } } }
public bool CanEditFile(IGC_File file, IGC_User user) { if (user.isAdmin) { return(true); } else { if (file.protectedFile) { return(false); } } if (file.editGroups.Count == 0) { if (file.accessGroups.Count == 0) { return(true); } foreach (IGC_UserGroup accessGroup in file.accessGroups) { if (user.groups.Contains(accessGroup)) { return(true); } } } foreach (IGC_UserGroup editGroup in file.editGroups) { if (user.groups.Contains(editGroup)) { return(true); } } return(false); }
private string ProtectedYN() { if (argv.Length != 4) { return(malformed_error + "\nusage: file -a <filename> <y|n>"); } bool pro = argv [3] == "y" ? true : false; IGC_URL url = fs.ParseURL(argv [2], issuer.cwd); IGC_File file = fs.GetFile(url.fullpath); if (file == null) { return(url.fullpath + " does not exist"); } if (fs.CanAccessFile(file, issuer)) { file.Protect(pro); return(url.fullpath + " is now " + (pro ? "protected" : "unprotected")); } return("you do not have permission to alter this file"); }
public void OnSystemReady() { startUpTasksComplete = true; //users file IGC_File etcUsers = fileSystem.GetFile("/etc/users"); if (etcUsers == null) { etcUsers = fileSystem.CreateFile(fileSystem.ParseURL("/etc/users", "/"), userRegistry.rootUser, false); } etcUsers.data = GetUsersString(SystemStateString()); //groups file IGC_File etcGroups = fileSystem.GetFile("/etc/groups"); if (etcGroups == null) { etcGroups = fileSystem.CreateFile(fileSystem.ParseURL("/etc/groups", "/"), userRegistry.rootUser, false); } etcGroups.data = GetGroupsString(SystemStateString()); gameObject.GetComponent <InGameComputer>().OnVirtualSystemReady(); }
[RPC] void SyncEditedFileRPC(string filepath, string data) { lastEditedFile = computer.virtualSystem.fileSystem.GetFile(filepath); rawEditString = data; }
public void EnterEditMode(IGC_File targetFile) { StartCoroutine(SetupEditMode(targetFile)); inputMode = (int)inputModes.TextEdit; }