///<summary> /// Encrypt and save the current engine state to file, so it can be loaded later. /// If file with the same name exists it won't be replaced, /// but to the current filename will be added a number, 'filename(1).acc' e.g. ///</summary> ///<param name="password"> /// The password to encrypt the file. ///</param> ///<param name="savePath"> /// The folder to save in. /// If not setted, the file will be saved in "pSavepath". ///</param> public string FileSaveSafe(string password, string savePath = "") { if (!Initial("FileSaveSafe()")) { return(null); } try { if (savePath == "") { savePath = pSavepath + FileName; } else { if (savePath[savePath.Length - 1] != '\\') { savePath += '\\'; } savePath += FileName; } if (Validators.ValidateWriteAccess(savePath) == false) { Fault("You don't have write access!"); return(savePath); } byte[] buff = IO.Serialize(Memory); byte[] crypted = IO.EncryptBytes(buff, password); IO.SaveSafe(savePath, crypted); Success(FileName + " Saved!"); return(savePath); } catch (Exception ex) { Exceptional(ex); return(null); } }
///<summary> /// Save the current engine state to file, so it can be loaded later. /// If FileName property is not set, the FileName is a string, representing a timestamp. ///</summary> ///<param name="savePath"> /// The folder to save in. /// If not setted, the file will be saved in "pSavepath". ///</param> public string FileSave(string savePath = "") { if (!Initial("FileSave()")) { return(null); } try { if (savePath == "") { savePath = pSavepath + FileName; } else { if (savePath[savePath.Length - 1] != '\\') { savePath += '\\'; } savePath += FileName; } if (Validators.ValidateWriteAccess(savePath) == false) { Fault("You don't have write access!"); return(savePath); } IO.Serialize(savePath, Memory); Success(FileName + " Saved!"); return(savePath); } catch (Exception ex) { Exceptional(ex); return(null); } }
///<summary> /// Scramble lines in text file. ///</summary> ///<param name="path"> /// The full path of the file or the relative one from pSavepath. ///</param> public string FileScramble(string path = "") { if (!Initial("FileScramble()")) { return(null); } try { if (path == "") { path = pSavepath + FileName; } else { if (path[path.Length - 1] != '\\') { path += '\\'; } path += FileName; } if (!Directory.Exists(path) && Validators.ValidateWriteAccess(path) == false) { Fault("You don't have write access!"); return(path);; } IO.Scramble(path); Success(FileName + " Scrambled!"); return(path); } catch (Exception ex) { Exceptional(ex); return(path); } }
///<summary> /// Save to a file. ///</summary> ///<param name="fileName"> /// The filename to be used in format: [filename].[extention]. ///</param> ///<param name="savePath"> /// The folder to save in. /// If not setted, the file will be saved in "pSavepath". ///</param> public string FileExport(string fileName = "", string savePath = "") { if (!Initial("FileExport()")) { return(null); } try { if (fileName == "") { fileName = FileName; } if (savePath == "") { savePath = pSavepath + fileName; } else { if (savePath[savePath.Length - 1] != '\\') { savePath += '\\'; } savePath += fileName; } if (Validators.ValidateWriteAccess(savePath) == false) { Fault("You don't have write access!"); return(savePath); } object obj = GetS(); if (obj is byte[] == false && obj is string == false && obj is string[] == false && obj is IEnumerable <object> == false) { Fault("Invalid value!"); return(savePath); } if (obj is string) { string str = obj as string; IO.Save(savePath, str); Success(fileName + " Saved! " + str.Length.ToString() + " chars of data written!"); return(savePath); } else if (obj is string[]) { string str = String.Join(Environment.NewLine, obj as string[]); IO.Save(savePath, str); Success(fileName + " Saved! " + (obj as string[]).Count().ToString() + " lines written!"); return(savePath); } else if (obj is byte[]) { byte[] buff = obj as byte[]; IO.Save(savePath, buff); Success(fileName + " Saved! " + buff.Count() + " bytes of data written!"); return(savePath); } Fault("Invalid value!"); return(null); } catch (Exception ex) { Exceptional(ex); return(null); } }