// this function will create a new entry and add it to the list then // return its index public int AddEntry(string name, double[] signal, double[] fft, int numSamples, uint temperature, byte battLife) { SignatureEntry entry = new SignatureEntry(name, signal, fft, numSamples, temperature, battLife); Table.Add(entry); NumEntries++; return Table.Count - 1; }
public int AddEntry(string name, double[] signal, double[] fft, int numSamples) { SignatureEntry entry = new SignatureEntry(name, signal, fft, numSamples); Table.Add(entry); NumEntries++; return Table.Count - 1; }
// this function will create a new entry and add it to the list then // return its index public int AddEntry(string name, double[] signal, double[] fft, int numSamples, uint temperature, byte battLife) { SignatureEntry entry = new SignatureEntry(name, signal, fft, numSamples, temperature, battLife); Table.Add(entry); NumEntries++; return(Table.Count - 1); }
public int AddEntry(string name, double[] signal, double[] fft, int numSamples) { SignatureEntry entry = new SignatureEntry(name, signal, fft, numSamples); Table.Add(entry); NumEntries++; return(Table.Count - 1); }
/// <summary> /// Reads shader signature from bytecode. /// </summary> /// <param name="bytecode">Bytecode.</param> /// <param name="token">Signature token: Possible values are 'ISGN', 'OSGN', 'OSG5'.</param> /// <returns>Array if signature entries.</returns> public static SignatureEntry[] ParseSignature(byte[] bytecode, string token) { int length = 0; var start = GetTokenPosition(bytecode, token, out length); if (start < 0) { return(null); } start += 4; // move start behind token. SignatureEntry[] sig = null; using (var ms = new MemoryStream(bytecode, start, bytecode.Length - start)) { using (var sr = new BinaryReader(ms)) { int sigSize = sr.ReadInt32(); int sigCount = sr.ReadInt32(); int dummy = sr.ReadInt32(); // always 8 //Log.Message(" - start:{3} sz:{0} cnt:{1} dummy:{2}", sigSize, sigCount, dummy, start ); sig = new SignatureEntry[sigCount]; for (int i = 0; i < sigCount; i++) { var sigEntry = new SignatureEntry(); if (token == "OSG5") { sigEntry.OsgM = sr.ReadInt32(); sigEntry.Name = ReadNullTermASCIIString(bytecode, start + sr.ReadInt32() + 4); sigEntry.Index = sr.ReadInt32(); sigEntry.SysValue = sr.ReadInt32(); sigEntry.Format = sr.ReadInt32(); sigEntry.Register = sr.ReadInt32(); sigEntry.Mask = sr.ReadInt32(); } else { sigEntry.Name = ReadNullTermASCIIString(bytecode, start + sr.ReadInt32() + 4); sigEntry.Index = sr.ReadInt32(); sigEntry.SysValue = sr.ReadInt32(); sigEntry.Format = sr.ReadInt32(); sigEntry.Register = sr.ReadInt32(); sigEntry.Mask = sr.ReadInt32(); } sig[i] = sigEntry; } } } return(sig); }
void SignatureGUI(MemberSession member, int sectionIndex, List <string> signatureList, int signatureIndex, bool readOnly) { string sig = signatureList[signatureIndex]; SignatureEntry sigEntry = member.Member.GetSignature(sig, true); bool edit = !readOnly && !m_Browser.translating && member.Member.MultipleSignaturesPossible; EditorGUI.BeginChangeCheck(); GUILayout.BeginHorizontal(); if (edit) { GUILayout.Space(4); Rect rect = GUILayoutUtility.GetRect(14, 14, GUILayout.ExpandWidth(false)); rect.y += 4; DocBrowser.DragHandle(rect, typeof(SignatureEntry), signatureList, signatureIndex, DocBrowser.styles.dragHandle); if (!sigEntry.InAsm || sigEntry.Asm.Private) { GUILayout.Space(4); rect = GUILayoutUtility.GetRect(14, 14, GUILayout.ExpandWidth(false)); rect.y += 4; if (MiniButton(rect, DocBrowser.styles.iconRemove)) { signatureList.RemoveAt(signatureIndex); } } } string sigString = m_Browser.ShowRawNames ? sigEntry.Name : sigEntry.FormattedHTML; if (sigEntry.InAsm && sigEntry.Asm.Private) { sigString = "<b><color=red>private</color></b> " + sigString; } GUILayout.Label(sigString, DocBrowser.styles.signature); GUILayout.EndHorizontal(); // Handle dragging Rect dragTargetRect = GUILayoutUtility.GetRect(10, 0); dragTargetRect.y -= 3; dragTargetRect.height = 14; DocBrowser.DragTarget(dragTargetRect, typeof(SignatureEntry), signatureList, signatureIndex + 1); if (EditorGUI.EndChangeCheck()) { member.OnModelEdited(true); } }
public void ProcessAsm(MemberItem member) { foreach (var sig in SignatureList) { // Don't include private signatures. We don't want the parameter list to include parameters used in private signatures only. SignatureEntry signature = member.GetSignature(sig); if (signature == null) { continue; } if (!signature.InAsm) { continue; } // Handle parameters System.Diagnostics.Debug.Assert(signature.Asm != null, "SignatureEntry.m_Asm for " + sig + " is null in ProcessAsm."); if (signature.Asm == null) { throw new Exception("SignatureEntry.m_Asm for " + sig + " is null in ProcessAsm."); } System.Diagnostics.Debug.Assert(signature.Asm.ParamList != null, "SignatureEntry.m_Asm.m_ParamList for " + sig + " is null in ProcessAsm."); if (signature.Asm.ParamList == null) { throw new Exception("SignatureEntry.m_Asm.m_ParamList for " + sig + " is null in ProcessAsm."); } foreach (ParamElement param in signature.Asm.ParamList) { ParameterWithDoc paramWithDoc = GetParameter(param.Name); if (paramWithDoc == null) { paramWithDoc = new ParameterWithDoc(param.Name); Parameters.Add(paramWithDoc); } paramWithDoc.AddType(param.Type); } // Handle return type if (ReturnDoc != null) { if (ReturnDoc.HasAsm) { if (ReturnDoc.ReturnType != signature.Asm.ReturnType) { throw new Exception("Different return types in the same MeaningfulBlock."); } } else { ReturnDoc.ReturnType = signature.Asm.ReturnType; } } } }
/// <summary> /// Reads shader signature from bytecode. /// </summary> /// <param name="bytecode">Bytecode.</param> /// <param name="token">Signature token: Possible values are 'ISGN', 'OSGN', 'OSG5'.</param> /// <returns>Array if signature entries.</returns> public static SignatureEntry[] ParseSignature( byte[] bytecode, string token ) { int length = 0; var start = GetTokenPosition( bytecode, token, out length ); if (start<0) { return null; } start += 4; // move start behind token. SignatureEntry[] sig = null; using ( var ms = new MemoryStream( bytecode, start, bytecode.Length - start ) ) { using ( var sr = new BinaryReader( ms ) ) { int sigSize = sr.ReadInt32(); int sigCount = sr.ReadInt32(); int dummy = sr.ReadInt32(); // always 8 //Log.Message(" - start:{3} sz:{0} cnt:{1} dummy:{2}", sigSize, sigCount, dummy, start ); sig = new SignatureEntry[ sigCount ]; for ( int i=0; i<sigCount; i++ ) { var sigEntry = new SignatureEntry(); if (token=="OSG5") { sigEntry.OsgM = sr.ReadInt32(); sigEntry.Name = ReadNullTermASCIIString( bytecode, start + sr.ReadInt32() + 4 ); sigEntry.Index = sr.ReadInt32(); sigEntry.SysValue = sr.ReadInt32(); sigEntry.Format = sr.ReadInt32(); sigEntry.Register = sr.ReadInt32(); sigEntry.Mask = sr.ReadInt32(); } else { sigEntry.Name = ReadNullTermASCIIString( bytecode, start + sr.ReadInt32() + 4 ); sigEntry.Index = sr.ReadInt32(); sigEntry.SysValue = sr.ReadInt32(); sigEntry.Format = sr.ReadInt32(); sigEntry.Register = sr.ReadInt32(); sigEntry.Mask = sr.ReadInt32(); } sig[i] = sigEntry; } } } return sig; }
public static bool TryPatchMC(IntPtr hProcess, IntPtr baseAddress) { IntPtr zero = IntPtr.Zero; long codeAddr = -1L; byte[] textSectionData = GetSectionBytes(hProcess, baseAddress, ".text", ref zero); SignatureEntry entry = _mcSigs.FirstOrDefault <SignatureEntry>(sig => (codeAddr = SearchPatternBytes(textSectionData, sig.Bytes, sig.Signature)) != -1L); if (entry == null) { return(false); } IntPtr lpAddr = new IntPtr((zero.ToInt64() + codeAddr) + entry.Offset); WriteByte(hProcess, lpAddr, 0xeb); return(true); }
static TibiaClient() { List <SignatureEntry> list = new List <SignatureEntry>(); SignatureEntry item = new SignatureEntry { Bytes = new byte[] { 0x80, 0xbd, 0x70, 0xf4, 0xff, 0xff, 0, 0x75, 0x40, 0x68, 0xd4, 0x77, 0x70, 0, 0x6a, 0, 0x6a, 0, 0xff, 0x15, 12, 0x42, 0x6c, 0, 0x8b, 0x3d, 0xf4, 0x41, 0x6c, 0, 0xff, 0xd7, 0x3d, 0xb7, 0, 0, 0, 0x74, 7, 0xff, 0xd7, 0x83, 0xf8, 5, 0x75, 0x1b }, Signature = "x?????xx?x????xxxxx?????x?????xxxxxxxx?xxxxxx?", Offset = 7 }; list.Add(item); SignatureEntry entry2 = new SignatureEntry { Bytes = new byte[] { 0x8a, 0x45, 0xe7, 0x84, 0xc0, 0x75, 0x52, 0x68, 60, 4, 0x5d, 0, 0x6a, 0, 0x6a, 0, 0xff, 0x15, 0xe4, 0xa2, 0x5b, 0, 0x89, 0x45, 0x98, 0x8b, 0x3d, 0x38, 0xa2, 0x5b, 0, 0xff, 0xd7, 0x3d, 0xb7, 0, 0, 0, 0x74, 11, 0xff, 0xd7, 0x83, 0xf8, 5, 0x74, 4 }, Signature = "x??xxx?x????xxxxx?????x??x?????xxxxxxxx?xxxxxx?", Offset = 5 }; list.Add(entry2); SignatureEntry entry3 = new SignatureEntry { Bytes = new byte[] { 0x8a, 0x45, 0xeb, 0x84, 0xc0, 0x75, 0x5f, 0x6a, 0, 0x68, 0x30, 0xdb, 0x44, 0, 0xc7, 5, 240, 0x45, 0x5f, 0, 0, 0, 0, 0, 0xff, 0x15, 0x74, 0xe4, 0x47, 0, 0xa1, 240, 0x45, 0x5f, 0, 0x85, 0xc0, 0x75, 0x2c, 0x6a, 0x30, 0x68, 180, 0xda, 0x48, 0, 0x68, 0x2c, 0xed, 0x48, 0, 0x6a, 0, 0xff, 0x15, 0x84, 0xe4, 0x47, 0 }, Signature = "x??xxx?xxx????x????xxxxxx?????x????xxx?xxx????x????xxx?????", Offset = 5 }; list.Add(entry3); _mcSigs = list; }
// this function will add an entry to the table and return its index public int AddSignature(SignatureEntry entry) { Table.Add(entry); NumEntries++; return(Table.Count - 1); }
/// <summary> /// Adds a content and signature hash to the manifest /// </summary> /// <param name="contenthash">The content hash</param> /// <param name="signaturehash">The signature hash</param> public void AddEntries(ContentEntry contenthash, SignatureEntry signaturehash) { SignatureHashes.Add(new HashEntry(signaturehash)); ContentHashes.Add(new HashEntry(contenthash)); }
public string Backup(string[] sources) { BackupStatistics bs = new BackupStatistics(XervBackupOperationMode.Backup); SetupCommonOptions(bs); BackendWrapper backend = null; VerificationFile verification = null; if (m_options.DontReadManifests) throw new Exception(Strings.Interface.ManifestsMustBeReadOnBackups); if (m_options.SkipFileHashChecks) throw new Exception(Strings.Interface.CannotSkipHashChecksOnBackup); if (sources == null || sources.Length == 0) throw new Exception(Strings.Interface.NoSourceFoldersError); //Make sure they all have the same format and exist for (int i = 0; i < sources.Length; i++) { sources[i] = Utility.Utility.AppendDirSeparator(System.IO.Path.GetFullPath(sources[i])); if (!System.IO.Directory.Exists(sources[i])) throw new System.IO.IOException(String.Format(Strings.Interface.SourceFolderIsMissingError, sources[i])); } //Sanity check for duplicate folders and multiple inclusions of the same folder for (int i = 0; i < sources.Length - 1; i++) { for (int j = i + 1; j < sources.Length; j++) if (sources[i].Equals(sources[j], Utility.Utility.IsFSCaseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase)) throw new Exception(string.Format(Strings.Interface.SourceDirIsIncludedMultipleTimesError, sources[i])); else if (sources[i].StartsWith(sources[j], Utility.Utility.IsFSCaseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase)) throw new Exception(string.Format(Strings.Interface.SourceDirsAreRelatedError, sources[i], sources[j])); } if (m_options.AsynchronousUpload) { m_asyncReserved = ASYNC_RESERVED; m_allowUploadProgress = false; } //Unused, but triggers errors in the encryption setup here Library.Interface.IEncryption encryptionModule = m_options.NoEncryption ? null : DynamicLoader.EncryptionLoader.GetModule(m_options.EncryptionModule, m_options.Passphrase, m_options.RawOptions); using (new Logging.Timer("Backup from " + string.Join(";", sources) + " to " + m_backend)) { try { if (OperationStarted != null) OperationStarted(this, XervBackupOperation.Backup, bs.OperationMode, -1, -1, Strings.Interface.StatusLoadingFilelist, ""); OperationProgress(this, XervBackupOperation.Backup, bs.OperationMode, -1, -1, Strings.Interface.StatusLoadingFilelist, ""); CheckLiveControl(); bool full = m_options.Full; if (full) bs.SetTypeReason(string.Format(Strings.Interface.FullBecauseFlagWasSet, "full")); backend = new BackendWrapper(bs, m_backend, m_options); backend.ProgressEvent += new XervBackup.Library.Main.RSync.RSyncDir.ProgressEventDelegate(BackupTransfer_ProgressEvent); backend.AsyncItemProcessedEvent += new EventHandler(backend_AsyncItemProcessedEvent); m_progress = 0.0; OperationProgress(this, XervBackupOperation.Backup, bs.OperationMode, (int)(m_progress * 100), -1, Strings.Interface.StatusReadingIncrementals, ""); CheckLiveControl(); List<ManifestEntry> backupsets; if (full) { //This will create the target folder backend.List(false); backupsets = new List<ManifestEntry>(); } else { //This will list all files on the backend and create the target folder backupsets = backend.GetBackupSets(); } if (backupsets.Count == 0) { if (!full) bs.SetTypeReason(Strings.Interface.FullBecauseBackendIsEmpty); full = true; } else { //A prioir backup exists, extract the compression and encryption modules used in the most recent entry string compression = null; string encryption = null; for (int i = backupsets.Count - 1; compression == null && i >= 0; i--) { for (int j = backupsets[i].Incrementals.Count - 1; compression == null && j >= 0; j--) for (int k = backupsets[i].Incrementals[j].Volumes.Count - 1; compression == null && k >= 0; k--) { compression = backupsets[i].Incrementals[j].Volumes[k].Key.Compression; encryption = backupsets[i].Incrementals[j].Volumes[k].Key.EncryptionMode; if (compression != null) break; } for (int k = backupsets[i].Volumes.Count - 1; compression == null && k >= 0; k--) { compression = backupsets[i].Volumes[k].Key.Compression; encryption = backupsets[i].Volumes[k].Key.EncryptionMode; if (compression != null) break; } } if (compression != null) { m_options.SetEncryptionModuleDefault(encryption); m_options.SetCompressionModuleDefault(compression); } } string fullCriteria1 = null; string fullCriteria2 = null; if (!full) { full = DateTime.Now > m_options.FullIfOlderThan(backupsets[backupsets.Count - 1].Time); if (full) bs.SetTypeReason(string.Format(Strings.Interface.FullBecauseLastFullIsFrom, backupsets[backupsets.Count - 1].Time, m_options.FullIfOlderThanValue)); else if (!string.IsNullOrEmpty(m_options.FullIfOlderThanValue)) fullCriteria1 = string.Format(Strings.Interface.IncrementalBecauseLastFullIsFrom, backupsets[backupsets.Count - 1].Time, m_options.FullIfOlderThanValue); } if (!full && m_options.FullIfMoreThanNIncrementals > 0) { full = backupsets[backupsets.Count - 1].Incrementals.Count >= m_options.FullIfMoreThanNIncrementals; if (full) bs.SetTypeReason(string.Format(Strings.Interface.FullBecauseThereAreNIncrementals, backupsets[backupsets.Count - 1].Incrementals.Count, m_options.FullIfMoreThanNIncrementals)); else fullCriteria2 = string.Format(Strings.Interface.IncrementalBecauseThereAreNIncrementals, backupsets[backupsets.Count - 1].Incrementals.Count, m_options.FullIfMoreThanNIncrementals); } bs.Full = full; if (!full) { if (fullCriteria1 == null && fullCriteria2 == null) bs.SetTypeReason(Strings.Interface.IncrementalBecauseNoFlagsWereSet); else if (fullCriteria2 == null) bs.SetTypeReason(fullCriteria1); else if (fullCriteria1 == null) bs.SetTypeReason(fullCriteria2); else bs.SetTypeReason(fullCriteria1 + ". " + fullCriteria2); } List<string> controlfiles = new List<string>(); if (!string.IsNullOrEmpty(m_options.SignatureControlFiles)) controlfiles.AddRange(m_options.SignatureControlFiles.Split(System.IO.Path.PathSeparator)); int vol = 0; long totalsize = 0; Manifestfile manifest = new Manifestfile(); using (Utility.TempFolder tempfolder = new XervBackup.Library.Utility.TempFolder()) { List<KeyValuePair<ManifestEntry, Library.Interface.ICompression>> patches = new List<KeyValuePair<ManifestEntry, XervBackup.Library.Interface.ICompression>>(); if (!full) { m_incrementalFraction = INCREMENAL_COST; List<ManifestEntry> entries = new List<ManifestEntry>(); entries.Add(backupsets[backupsets.Count - 1]); entries.AddRange(backupsets[backupsets.Count - 1].Incrementals); //Check before we start the download CheckLiveControl(); VerifyBackupChainWithFiles(backend, entries[entries.Count - 1]); if (m_options.CreateVerificationFile) verification = new VerificationFile(entries, backend.FilenameStrategy); OperationProgress(this, XervBackupOperation.Backup, bs.OperationMode, (int)(m_progress * 100), -1, Strings.Interface.StatusReadingIncrementals, ""); patches = FindPatches(backend, entries, tempfolder, false, bs); //Check before we start the download CheckLiveControl(); Manifestfile latest = GetManifest(backend, backupsets[backupsets.Count - 1]); //Manifest version 1 does not support multiple folders if (latest.Version == 1) latest.SourceDirs = new string[] { sources[0] }; if (latest.SourceDirs.Length != sources.Length) { if (m_options.FullIfSourceFolderChanged) { Logging.Log.WriteMessage("Source folder count changed, issuing full backup", XervBackup.Library.Logging.LogMessageType.Information); if (!full) bs.SetTypeReason(Strings.Interface.FullBecauseSourceFoldersChanged); full = true; } else throw new Exception(string.Format(Strings.Interface.NumberOfSourceFoldersHasChangedError, latest.SourceDirs.Length, sources.Length)); } else { if (!m_options.AllowSourceFolderChange) { foreach (string s1 in latest.SourceDirs) { bool found = false; foreach (string s2 in sources) if (s1.Equals(s2, Utility.Utility.IsFSCaseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase)) { found = true; break; } if (!found) { if (m_options.FullIfSourceFolderChanged) { Logging.Log.WriteMessage("Source folders changed, issuing full backup", XervBackup.Library.Logging.LogMessageType.Information); if (!full) bs.SetTypeReason(Strings.Interface.FullBecauseSourceFoldersChanged); full = true; break; //Exit the folder loop } else throw new Exception(string.Format(Strings.Interface.SourceFoldersHasChangedError, s1)); } } manifest.SourceDirs = latest.SourceDirs; } else { manifest.SourceDirs = sources; } } } DateTime backuptime = DateTime.Now; DateTime backupchaintime; if (full) { patches.Clear(); m_incrementalFraction = 0.0; manifest.SourceDirs = sources; if (m_options.CreateVerificationFile) verification = new VerificationFile(new ManifestEntry[0], backend.FilenameStrategy); backupchaintime = backuptime; } else { backupchaintime = patches[0].Key.Time; manifest.PreviousManifestFilename = patches[patches.Count - 1].Key.Filename; manifest.PreviousManifestHash = patches[patches.Count - 1].Key.RemoteHash; } OperationProgress(this, XervBackupOperation.Backup, bs.OperationMode, -1, -1, Strings.Interface.StatusBuildingFilelist, ""); bool completedWithoutChanges; using (RSync.RSyncDir dir = new XervBackup.Library.Main.RSync.RSyncDir(manifest.SourceDirs, bs, m_options.Filter, patches)) { CheckLiveControl(); dir.ProgressEvent += new XervBackup.Library.Main.RSync.RSyncDir.ProgressEventDelegate(BackupRSyncDir_ProgressEvent); dir.DisableFiletimeCheck = m_options.DisableFiletimeCheck; dir.MaxFileSize = m_options.SkipFilesLargerThan; using (new Logging.Timer("Initiating multipass")) dir.InitiateMultiPassDiff(full, m_options); string tempVolumeFolder = m_options.AsynchronousUpload ? m_options.AsynchronousUploadFolder : m_options.TempDir; bool done = false; while (!done && totalsize < m_options.MaxSize) { using (new Logging.Timer("Multipass " + (vol + 1).ToString())) using (Utility.TempFile signaturefile = new XervBackup.Library.Utility.TempFile(System.IO.Path.Combine(tempVolumeFolder, Guid.NewGuid().ToString()))) using (Utility.TempFile contentfile = new XervBackup.Library.Utility.TempFile(System.IO.Path.Combine(tempVolumeFolder, Guid.NewGuid().ToString()))) { OperationProgress(this, XervBackupOperation.Backup, bs.OperationMode, (int)(m_progress * 100), -1, string.Format(Strings.Interface.StatusCreatingVolume, vol + 1), ""); CheckLiveControl(); using (Library.Interface.ICompression signaturearchive = DynamicLoader.CompressionLoader.GetModule(m_options.CompressionModule, signaturefile, m_options.RawOptions)) using (Library.Interface.ICompression contentarchive = DynamicLoader.CompressionLoader.GetModule(m_options.CompressionModule, contentfile, m_options.RawOptions)) { //If we are all out, stop now, this may cause incomplete partial files if (m_options.MaxSize - totalsize < (contentarchive.FlushBufferSize + backend.FileSizeOverhead)) break; //Add signature files to archive foreach (string s in controlfiles) if (!string.IsNullOrEmpty(s)) using (System.IO.Stream cs = signaturearchive.CreateFile(System.IO.Path.Combine(RSync.RSyncDir.CONTROL_ROOT, System.IO.Path.GetFileName(s)))) using (System.IO.FileStream fs = System.IO.File.OpenRead(s)) Utility.Utility.CopyStream(fs, cs); //Only add control files to the very first volume controlfiles.Clear(); done = dir.MakeMultiPassDiff(signaturearchive, contentarchive, (Math.Min(m_options.VolumeSize, m_options.MaxSize - totalsize)) - backend.FileSizeOverhead); //TODO: This is not the correct size, we need to account for file size overhead as well totalsize += signaturearchive.Size; totalsize += contentarchive.Size; //TODO: This is not the best way to determine this if (totalsize >= m_options.MaxSize) dir.FinalizeMultiPass(signaturearchive, contentarchive, long.MaxValue); } completedWithoutChanges = done && !dir.AnyChangesFound; if (m_options.UploadUnchangedBackups || full) completedWithoutChanges = false; if (!completedWithoutChanges) { if (m_options.AsynchronousUpload) { m_lastProgressMessage = Strings.Interface.StatusWaitingForUpload; m_allowUploadProgress = true; m_allowUploadProgressAfter = DateTime.Now.AddSeconds(1); } else OperationProgress(this, XervBackupOperation.Backup, bs.OperationMode, (int)(m_progress * 100), -1, string.Format(Strings.Interface.StatusUploadingContentVolume, vol + 1), ""); //Last check before we upload, we do not interrupt transfers CheckLiveControl(); //The backendwrapper will remove these signaturefile.Protected = true; contentfile.Protected = true; ContentEntry ce = new ContentEntry(backuptime, full, vol + 1); SignatureEntry se = new SignatureEntry(backuptime, full, vol + 1); using (new Logging.Timer("Writing delta file " + (vol + 1).ToString())) backend.Put(ce, contentfile); if (!m_options.AsynchronousUpload) OperationProgress(this, XervBackupOperation.Backup, bs.OperationMode, (int)(m_progress * 100), -1, string.Format(Strings.Interface.StatusUploadingSignatureVolume, vol + 1), ""); using (new Logging.Timer("Writing remote signatures")) backend.Put(se, signaturefile); manifest.AddEntries(ce, se); if (verification != null) { verification.AddFile(ce); verification.AddFile(se); } } } if (!completedWithoutChanges) { //The backend wrapper will remove these Utility.TempFile mf = new XervBackup.Library.Utility.TempFile(); using (new Logging.Timer("Writing manifest " + backuptime.ToUniversalTime().ToString("yyyyMMddTHHmmssK"))) { //Alternate primary/secondary ManifestEntry mfe = new ManifestEntry(backuptime, full, manifest.SignatureHashes.Count % 2 != 0); manifest.SelfFilename = backend.GenerateFilename(mfe); manifest.Save(mf); if (!m_options.AsynchronousUpload) OperationProgress(this, XervBackupOperation.Backup, bs.OperationMode, (int)(m_progress * 100), -1, string.Format(Strings.Interface.StatusUploadingManifestVolume, vol + 1), ""); //Write the file mf.Protected = true; backend.Put(mfe, mf); if (verification != null) verification.UpdateManifest(mfe); } if (verification != null) { using (new Logging.Timer("Writing verification " + backuptime.ToUniversalTime().ToString("yyyyMMddTHHmmssK"))) { Utility.TempFile vt = new XervBackup.Library.Utility.TempFile(); verification.Save(vt); if (!m_options.AsynchronousUpload) OperationProgress(this, XervBackupOperation.Backup, bs.OperationMode, (int)(m_progress * 100), -1, Strings.Interface.StatusUploadingVerificationVolume, ""); vt.Protected = true; backend.Put(new VerificationEntry(backupchaintime), vt); } } if (m_options.AsynchronousUpload) m_allowUploadProgress = false; //The file volume counter vol++; } } } //If we are running asynchronous, we now enter the end-game if (m_options.AsynchronousUpload) { m_lastProgressMessage = Strings.Interface.StatusWaitingForUpload; m_allowUploadProgress = true; m_allowUploadProgressAfter = DateTime.Now; //Before we clear the temp folder, we need to ensure that all volumes are uploaded. //To allow the UI to show some progress while uploading, we perform the remaining // uploads synchronous List<KeyValuePair<BackupEntryBase, string>> pendingUploads = backend.ExtractPendingUploads(); //Figure out what volume number we are at foreach (KeyValuePair<BackupEntryBase, string> p in pendingUploads) if (p.Key is ManifestEntry) vol--; double unitcost = m_asyncReserved / pendingUploads.Count; //The upload each remaining volume in order foreach (KeyValuePair<BackupEntryBase, string> p in pendingUploads) { string msg; if (p.Key is ManifestEntry) { vol++; msg = string.Format(Strings.Interface.StatusUploadingManifestVolume, vol); } else if (p.Key is SignatureEntry) msg = string.Format(Strings.Interface.StatusUploadingSignatureVolume, ((SignatureEntry)p.Key).Volumenumber); else if (p.Key is ContentEntry) { msg = string.Format(Strings.Interface.StatusUploadingContentVolume, ((ContentEntry)p.Key).Volumenumber); //We allow a stop or pause request here CheckLiveControl(); } else if (p.Key is VerificationEntry) msg = Strings.Interface.StatusUploadingVerificationVolume; else throw new InvalidOperationException(); OperationProgress(this, XervBackupOperation.Backup, bs.OperationMode, (int)(m_progress * 100), -1, msg, ""); backend.Put(p.Key, p.Value); m_asyncReserved -= unitcost; m_progress += unitcost; } } } } catch(Exception ex) { //If this is a controlled user-requested stop, wait for the current upload to complete if (backend != null && ex is LiveControl.ExecutionStoppedException) { try { if (m_options.AsynchronousUpload) { m_lastProgressMessage = Strings.Interface.StatusWaitingForUpload; m_allowUploadProgress = true; m_allowUploadProgressAfter = DateTime.Now; //Wait for the current upload to complete and then delete all remaining temporary files foreach (KeyValuePair<BackupEntryBase, string> p in backend.ExtractPendingUploads()) try { if (System.IO.File.Exists(p.Value)) System.IO.File.Delete(p.Value); } catch { } //Better to delete as many as possible rather than choke on a single file } } catch { } //We already have an exception, just go with that } if (backend == null || backend.ManifestUploads == 0) { Logging.Log.WriteMessage(string.Format(Strings.Interface.ErrorRunningBackup, ex.Message), Logging.LogMessageType.Error); throw; //This also activates "finally", unlike in other languages... } Logging.Log.WriteMessage(string.Format(Strings.Interface.PartialUploadMessage, backend.ManifestUploads, ex.Message), Logging.LogMessageType.Warning); bs.LogError(string.Format(Strings.Interface.PartialUploadMessage, backend.ManifestUploads, ex.Message), ex); } finally { m_progress = 100.0; if (backend != null) try { backend.Dispose(); } catch { } if (OperationCompleted != null) OperationCompleted(this, XervBackupOperation.Backup, bs.OperationMode, 100, -1, Strings.Interface.StatusCompleted, ""); OperationProgress(this, XervBackupOperation.Backup, bs.OperationMode, 100, -1, Strings.Interface.StatusCompleted, ""); } } bs.EndTime = DateTime.Now; return bs.ToString(); }
/// <summary> /// Searches the cache directory for a matching entry, returns null if no entry matches /// </summary> /// <param name="remote">The signature entry to search for</param> /// <returns>The filename to the cached copy or null</returns> private string FindCacheEntry(SignatureEntry remote) { if (remote == null) return null; if (string.IsNullOrEmpty(m_options.SignatureCachePath)) return null; string cachefilename = System.IO.Path.Combine(m_options.SignatureCachePath, m_cachefilenamestrategy.GenerateFilename(remote)); if (System.IO.File.Exists(cachefilename)) return cachefilename; //If the new filename does not exist, see if we can parse the older style short filenames instead if (!System.IO.File.Exists(cachefilename) && System.IO.Directory.Exists(m_options.SignatureCachePath)) foreach (string s in System.IO.Directory.GetFiles(m_options.SignatureCachePath)) { BackupEntryBase be = m_cachefilenamestrategy.ParseFilename(new Duplicati.Library.Interface.FileEntry(System.IO.Path.GetFileName(s))); if (be is SignatureEntry) { if (be.Time == remote.Time && be.IsFull == remote.IsFull && ((SignatureEntry)be).Volumenumber == ((SignatureEntry)remote).Volumenumber) return s; } } return null; }
public bool ReadTableFromFile(string filename) { // make sure file exists first if (!File.Exists(filename)) return false; // attempt to open the file using (TextReader t = new StreamReader(filename)) { // clear table first Table.Clear(); string line; string[] Fields, data; double[] numData; int i; SignatureEntry e; while ((line = t.ReadLine()) != null) { e = new SignatureEntry(); // parse the line Fields = line.Split(';'); if (Fields.Length < 3) continue; // get the name e.Name = Fields[0]; // grab the number of samples e.NumSamples = System.Convert.ToInt32(Fields[1]); // get temp and batt life e.Temperature = System.Convert.ToUInt32(Fields[2]); e.BattLife = System.Convert.ToByte(Fields[3]); // grab the signal data data = Fields[4].Split(','); numData = new double[data.Length]; i = 0; foreach (string d in data) { if (!d.Equals("")) numData[i++] = System.Convert.ToDouble(d); } e.Signal = numData; // grab the fft data data = Fields[5].Split(','); numData = new double[data.Length]; i = 0; foreach (string d in data) { if (!d.Equals("")) numData[i++] = System.Convert.ToDouble(d); } e.FFT = numData; // add to the database AddSignature(e); } } return true; }
public bool ReadTableFromFile(string filename) { // make sure file exists first if (!File.Exists(filename)) { return(false); } // attempt to open the file using (TextReader t = new StreamReader(filename)) { // clear table first Table.Clear(); string line; string[] Fields, data; double[] numData; int i; SignatureEntry e; while ((line = t.ReadLine()) != null) { e = new SignatureEntry(); // parse the line Fields = line.Split(';'); if (Fields.Length < 3) { continue; } // get the name e.Name = Fields[0]; // grab the number of samples e.NumSamples = System.Convert.ToInt32(Fields[1]); // get temp and batt life e.Temperature = System.Convert.ToUInt32(Fields[2]); e.BattLife = System.Convert.ToByte(Fields[3]); // grab the signal data data = Fields[4].Split(','); numData = new double[data.Length]; i = 0; foreach (string d in data) { if (!d.Equals("")) { numData[i++] = System.Convert.ToDouble(d); } } e.Signal = numData; // grab the fft data data = Fields[5].Split(','); numData = new double[data.Length]; i = 0; foreach (string d in data) { if (!d.Equals("")) { numData[i++] = System.Convert.ToDouble(d); } } e.FFT = numData; // add to the database AddSignature(e); } } return(true); }
// this function will add an entry to the table and return its index public int AddSignature(SignatureEntry entry) { Table.Add(entry); NumEntries++; return Table.Count - 1; }