///<summary> /// Save to a file. ///</summary> ///<param name="s"> /// The collection of strings to be saved. ///</param> ///<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(IList <string> s, 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); } IO.Save(savePath, s); Success(fileName + " Saved! " + s.Count().ToString() + " lines written!"); return(savePath); } catch (Exception ex) { Exceptional(ex); return(null); } }
///<summary> /// Encrypt and 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="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 FileSave(string password, 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); } byte[] buff = IO.Serialize(Memory); byte[] crypted = IO.EncryptBytes(buff, password); IO.Save(savePath, crypted); Success(FileName + " Saved!"); return(savePath); } catch (Exception ex) { Exceptional(ex); return(null); } }
///<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); } }