public void Backup(string filePath, string srcFolder, byte[] archHeader) { Initializing?.Invoke(); FilesBag bag = CreateBag(srcFolder); FileStream fsDest = null; try { fsDest = File.Create(filePath); var writer = new RawDataWriter(fsDest, Encoding.UTF8); writer.Write(Signature); writer.Write(DateTime.Now); writer.Write(archHeader.Length); writer.Write(archHeader); Compressing?.Invoke(); bag.Compress(fsDest); Done?.Invoke(); } catch { if (fsDest != null) { fsDest.Dispose(); File.Delete(filePath); } throw; } }
public void PostLog(string txt, bool isError) { var ms = new MemoryStream(); var writer = new RawDataWriter(ms, Encoding.UTF8); writer.Write(DateTime.Now); writer.Write(isError); writer.Write(txt); byte[] msgData = ms.ToArray(); PostMessage(Message_t.Log, msgData); }
void SaveData() { using (FileStream fs = File.Create(m_dataFilePath)) { var writer = new RawDataWriter(fs, Encoding.UTF8); writer.Write(FileSignature); writer.Write(m_entries.Count); foreach (Entry e in m_entries) { e.Write(writer); } } }
public void Start() { var ms = new MemoryStream(); var writer = new RawDataWriter(ms, Encoding.UTF8); ClientEnvironment clEnv = GetEnvironment(); writer.Write(m_clID); clEnv.Write(writer); writer.Write(DateTime.Now); m_msgData = ms.ToArray(); var task = new Task(PostReq, TaskCreationOptions.LongRunning); task.Start(); }
public static void AppendConnectionsResp(string filePath, IEnumerable <Message> messages) { Assert(messages != null); using (FileLocker.Lock(filePath)) using (FileStream fs = File.Open(filePath, FileMode.Open, FileAccess.ReadWrite)) { var reader = new RawDataReader(fs, Encoding.UTF8); int countPos = SrvCxnSignature.Length;; fs.Position = countPos; int msgCount = reader.ReadInt(); var writer = new RawDataWriter(fs, Encoding.UTF8); fs.Seek(0, SeekOrigin.End); foreach (Message msg in messages) { msg.Write(writer); ++msgCount; } fs.Position = countPos; writer.Write(msgCount); } }
public void Save() { using (FileStream fs = File.Create(SettingsManager.RunOnceFilePath)) { var writer = new RawDataWriter(fs, Encoding.UTF8); writer.Write(Signature); writer.Write(m_actions.Count); foreach (IRunOnceCommand act in m_actions) { writer.Write((int)act.ActionCode); act.Write(writer); } } }
void SaveAppSettings() { if (!Directory.Exists(AppDataFolder)) { Directory.CreateDirectory(AppDataFolder); } using (FileStream fs = File.Create(AppSettingsFilePath)) using (var xs = new XorStream(fs)) using (var gzs = new GZipStream(xs, CompressionMode.Compress)) { var writer = new RawDataWriter(xs, Encoding.UTF8); writer.Write(Encoding.UTF8.GetBytes(APP_SETTINGS_SIGNATURE)); writer.Write(m_dataGeneration); writer.Write(m_updateKey); } }
public static void SaveTablesUpdate(List <TableUpdate> updates, string filePath) { Assert(updates != null); using (FileStream fs = File.Create(filePath)) { var writer = new RawDataWriter(fs, Encoding.UTF8); writer.Write(Encoding.UTF8.GetBytes(TABLES_UPDATE_SIGNATURE)); writer.Write(updates.Count); foreach (TableUpdate update in updates) { PushTableUpdate(writer, update); } } }
public void Compress(FileStream fs) { //build folders list var folders = new List <string>(); var seq = from fd in m_files where fd.DestFolder != null select fd.DestFolder; folders.AddRange(seq.Distinct(StringComparer.OrdinalIgnoreCase)); using (var gzs = new GZipStream(fs, CompressionMode.Compress)) { var writer = new RawDataWriter(gzs, Encoding.UTF8); writer.Write(Signature); writer.Write(folders.Count); foreach (string folder in folders) { writer.Write(folder); } writer.Write(m_files.Count); foreach (FileData fd in m_files) { writer.Write(fd.FileName); if (fd.DestFolder == null) { writer.Write(NDX_CUR_FOLDER); } else { string dir = fd.DestFolder; int ndx = folders.FindIndex(x => string.Compare(dir, x, true) == 0); Assert(ndx >= 0); writer.Write(ndx); } using (FileStream fStream = File.OpenRead(fd.FilePath)) { writer.Write(fStream.Length); fStream.CopyTo(gzs); } FileCompressed?.Invoke(Path.Combine(fd.DestFolder ?? ".\\", fd.FileName)); } } }
public static void WriteConnectionsReq(string filePath, IEnumerable <Message> messages) { Assert(messages != null); using (FileLocker.Lock(filePath)) using (FileStream fs = File.Create(filePath)) { var writer = new RawDataWriter(fs, Encoding.UTF8); writer.Write(HubCxnSignature); writer.Write(messages.Count()); foreach (Message msg in messages) { msg.Write(writer); } } }
public static void WriteProfiles(string filePath, IEnumerable <ProfileInfo> profiles) { Assert(profiles != null); using (FileLocker.Lock(filePath)) using (FileStream fs = File.Create(filePath)) { var writer = new RawDataWriter(fs, Encoding.UTF8); writer.Write(ProfileSignature); writer.Write(profiles.Count()); foreach (ProfileInfo prInfo in profiles) { prInfo.Write(writer); } } }
void PostSyncMessage() { Action post = () => { var netEngin = new NetEngin(Program.NetworkSettings); string tmpFile = Path.GetTempFileName(); var ms = new MemoryStream(); var writer = new RawDataWriter(ms, Encoding.UTF8); writer.Write(m_clInfo.ClientID); writer.Write(m_srvLastMsgID); writer.Write(m_clientLastMsgID); byte[] msgData = ms.ToArray(); try { netEngin.Download(tmpFile, Urls.ConnectionReqURL); var seq = DialogEngin.ReadConnectionsReq(tmpFile); uint msgID = 0; if (seq.Any()) { msgID = seq.Max(m => m.ID); } var msg = new Message(msgID + 1, 0, Message_t.Sync, msgData); DialogEngin.AppendConnectionsReq(tmpFile, new Message[] { msg }); netEngin.Upload(Urls.ConnectionReqURL, tmpFile); } catch (Exception ex) { Dbg.Log("PostSyncMessage: " + ex.Message); } finally { File.Delete(tmpFile); } }; var task = new Task(post, TaskCreationOptions.LongRunning); task.Start(); }
public static void WriteAppManifest(string filePath, IReadOnlyDictionary <AppArchitecture_t, string> updates) { Assert(updates != null); using (FileStream fs = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { var writer = new RawDataWriter(fs, Encoding.UTF8); byte[] sign = Encoding.UTF8.GetBytes(APP_MANIFEST_SIGNATURE); writer.Write(sign); writer.Write(updates.Count); foreach (KeyValuePair <AppArchitecture_t, string> kv in updates) { writer.Write((byte)kv.Key); writer.Write(kv.Value); } } }
public static void WriteSrvDialog(string filePath, ClientDialog clDlg) { Assert(clDlg != null); using (FileLocker.Lock(filePath)) using (FileStream fs = File.Create(filePath)) { var writer = new RawDataWriter(fs, Encoding.UTF8); writer.Write(SrvDialogSignature); clDlg.Write(writer); } }
public static void UpdateDataManifest(string filePath, UpdateURI updateURI) { Assert(updateURI != null); using (FileStream fs = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { var writer = new RawDataWriter(fs, Encoding.UTF8); byte[] sign = Encoding.UTF8.GetBytes(DATA_MANIFEST_SIGNATURE); if (fs.Length == 0) { writer.Write(sign); writer.Write(1); } else { var reader = new RawDataReader(fs, Encoding.UTF8); for (int i = 0; i < sign.Length; ++i) { if (reader.ReadByte() != sign[i]) { throw new CorruptedFileException(filePath); } } int uriCount = reader.ReadInt(); fs.Position -= sizeof(int); writer.Write(uriCount + 1); fs.Seek(0, SeekOrigin.End); } writer.Write(updateURI.DataPreGeneration); writer.Write(updateURI.DataPostGeneration); writer.Write(updateURI.FileURI); } }
void SaveUserSettings() { if (!Directory.Exists(UserDataFolder)) { Directory.CreateDirectory(UserDataFolder); } using (FileStream fs = File.Create(UserSettingsFilePath)) using (var xs = new XorStream(fs)) using (var gzs = new GZipStream(xs, CompressionMode.Compress)) { var writer = new RawDataWriter(xs, Encoding.UTF8); writer.Write(Encoding.UTF8.GetBytes(USER_SETTINGS_SIGNATURE)); writer.Write(IsMaximized); writer.Write(FrameRectangle.Left); writer.Write(FrameRectangle.Top); writer.Write(FrameRectangle.Width); writer.Write(FrameRectangle.Height); writer.Write(UseCountryCode); writer.Write(MRUSubHeadingSize); writer.Write(MRUSubHeading.Count); foreach (SubHeading sh in MRUSubHeading) { writer.Write(sh.Value); } writer.Write(AutoDetectProxy); writer.Write(EnableProxy); writer.Write(ProxyHost ?? ""); writer.Write(ProxyPort); } }