private void UnpackFile(InstallerBinary objBinary, FileTableEntry entry, ref string strCurrentFileName) { string strFilePath = entry.Path; strFilePath = _objManager.ReplaceValueVariables(strFilePath); strCurrentFileName = strFilePath; if (System.IO.File.Exists(strFilePath)) { Globals.Logger.LogInfo("Overwriting " + strFilePath); } string dirname = System.IO.Path.GetDirectoryName(strFilePath); if (!System.IO.Directory.Exists(dirname)) { Globals.Logger.LogInfo("Creating " + dirname); System.IO.Directory.CreateDirectory(dirname); } byte[] fileBytes = objBinary.ReadFileBytes(entry); Globals.Logger.LogInfo("Writing File " + strFilePath); FileUtils.WriteBytesViaStream(strFilePath, fileBytes); // System.IO.File.WriteAllBytes(strFilePath, fileBytes); // InstalledFiles.Add(strFilePath); }
public void UnpackFiles(InstallerBinary objBinary, string strInstallRoot, ref double dblProgress, System.Threading.CancellationToken token, ref string strCurrentFile) { if (!System.IO.Directory.Exists(strInstallRoot)) { System.IO.Directory.CreateDirectory(strInstallRoot); } double dblInitialProgress = dblProgress; // Unpack all files. for (int iEntry = 0; iEntry < _lstEntries.Count; iEntry++) { FileTableEntry entry = _lstEntries[iEntry]; UnpackFile(objBinary, entry, ref strCurrentFile); dblProgress = dblInitialProgress + ((double)iEntry / (double)_lstEntries.Count * (1.0 - dblInitialProgress)); if (token.IsCancellationRequested) { token.ThrowIfCancellationRequested(); } } }
public static FileTableEntry Deserialize(InstallerBinary objBinary) { Int64 off = objBinary.ReadInt64(); Int64 size = objBinary.ReadInt64(); string path = objBinary.ReadUTF8Path(); FileTableEntry ret = new FileTableEntry(off, size, path); return(ret); }
public byte[] ReadFileBytes(FileTableEntry entry) { //Note: Entry.path is not correct here. byte[] buffer = new byte[entry.Size]; _objReader.BaseStream.Seek(entry.Offset, System.IO.SeekOrigin.Begin); _objReader.Read(buffer, 0, buffer.Length); return(buffer); }
public void Deserialize(InstallerBinary objBinary) { Int64 entries = objBinary.ReadInt64(); for (Int64 iEntry = 0; iEntry < entries; iEntry++) { FileTableEntry ent = FileTableEntry.Deserialize(objBinary); _lstEntries.Add(ent); } }
public void RemoveInstalledFiles( string strInstallRoot, ref double dblProgress, ref string strCurrentFile, double dblInitialProgress ) { Globals.Logger.LogInfo("Rolling back installation."); for (int iEntry = 0; iEntry < _lstEntries.Count; iEntry++) { FileTableEntry entry = _lstEntries[iEntry]; string strFilePath = entry.Path; try { strFilePath = _objManager.ReplaceValueVariables(strFilePath); strCurrentFile = strFilePath; if (System.IO.File.Exists(strFilePath)) { System.IO.File.Delete(strFilePath); } } catch (Exception ex) { Globals.Logger.LogError("Failed to delete file " + strFilePath + ".\r\n" + ex.ToString()); } dblProgress = dblInitialProgress + ((double)(_lstEntries.Count - iEntry) / (double)_lstEntries.Count); } /* foreach (string file in InstalledFiles) * { * strCurrentFile = file; * Globals.Logger.LogInfo("Deleting " + file); * try * { * System.IO.File.Delete(file); * } * catch (Exception ex) * { * Globals.Logger.LogError("Failed to delete file " + file + ".\r\n" + ex.ToString()); * } * // Show the progress bar "reversing" * dblProgress = dblInitialProgress + ((double)(InstalledFiles.Count - iEntry) / (double)InstalledFiles.Count); * iEntry++; * }*/ Globals.Logger.LogInfo("Current directory = " + System.IO.Directory.GetCurrentDirectory()); RemoveDeleteDirectoryRecursive(strInstallRoot); }