public void canStoreAndRetrieveFilesInWIM() { using (updateDB uut = new updateDB(connstr, testDBName, true)) { wsusUpdate sourcefile = new wsusUpdate("http://foo.cab", new byte[] { 0x11, 0x22, 0x33 }, 123); uut.insert_noconcurrency(sourcefile); sourcefile = uut.getWSUSFileByFileHash(new byte[] { 0x11, 0x22, 0x33 }); fileSource_wim imageEntry = new fileSource_wim("test", 2, "abc", 10); file_wimInfo testFileA = new file_wimInfo("test file A", new byte[] { 0x11, 0x22, 0x33 }, new byte[] { 0xaa, 0xbb }, imageEntry, "loc1"); file_wimInfo testFileB = new file_wimInfo("test file B", new byte[] { 0x44, 0x55, 0x66 }, new byte[] { 0xcc, 0xdd }, imageEntry, "loc1"); uut.bulkInsertFiles(sourcefile, new file_wimInfo[] { testFileA, testFileB }); // After insertion, the files should be correct List <file_wimInfo> A = uut.getWimInfos(); Assert.AreEqual(2, A.Count); Assert.AreEqual(imageEntry.wimImageName, A[0].parent.wimImageName); Assert.AreEqual(imageEntry.wimImageName, A[1].parent.wimImageName); Assert.AreEqual("test file A", A[0].fileInfo.filename); Assert.AreEqual("test file B", A[1].fileInfo.filename); Assert.AreEqual(sourcefile.dbID.Value, A[0].fileInfo.wsusFileID); Assert.AreEqual(sourcefile.dbID.Value, A[1].fileInfo.wsusFileID); } }
private static void Main(opts args) { using (updateDB db = new updateDB(args.connstr, args.dbname)) { // Make sure all delta files are represented in the deltafiles table, even if they are empty. List <file> deltaFiles = db.getDeltasFilesByPartialName("%ntoskrnl.exe"); foreach (file deltaFile in deltaFiles) { delta newdelta = new delta(deltaFile); Byte[] deltaBytes = new byte[deltaFile.contents128b.Length - 4]; Array.Copy(deltaFile.contents128b, 4, deltaBytes, 0, deltaBytes.Length); interop.DELTA_HEADER_INFO headerInfo = findHeaderForDelta(deltaBytes); newdelta.outputFileSize = (long)headerInfo.TargetSize; newdelta.deltaFileID = deltaFile.dbID.Value; db.insertOrCreateNoUpdate(newdelta, "deltas", new [] { "sourcefileID" }); } while (true) { // Next, go through the delta table, filling in anything we already have rows for. List <file> allFiles = db.getFilesByPartialName("%ntoskrnl.exe"); List <delta> deltas = db.getDeltasByFileIDs(deltaFiles.Select(x => x.dbID.Value).ToArray()); foreach (delta delta in deltas) { if (delta.sourceFileID == null) { applyDelta(db, allFiles, delta); } } } } }
public void testLoggingOfWIM() { using (updateDB uut = new updateDB(Program.connstr, Program.dbName, true)) { byte[] filehash = new byte[] { 0xe4, 0x13, 0x81, 0xb5, 0x3b, 0x64, 0x8f, 0x62, 0xc9, 0x1b, 0x13, 0xbd, 0xe5, 0x74, 0xc5, 0x03, 0x31, 0xf2, 0x20, 0x96 }; wsusUpdate sourcefile = new wsusUpdate( "http://b1.download.windowsupdate.com/c/upgr/2016/05/10586.0.160426-1409.th2_refresh_clienteducationn_vol_x86fre_lv-lv_793d7991cca6a99000f938b3743712f756af57b2.esd", filehash, 2059062476); uut.insert_noconcurrency(sourcefile); Program.Main(null); List <file> result = uut.getAllFiles(); List <string> errors = uut.getErrorStrings(); foreach (string error in errors) { Debug.WriteLine("Error: " + error); } // Assert.AreEqual(0, errors.Count); Assert.AreEqual(44199, result.Count); // TODO: more tests! } }
private static void applyDelta(updateDB db, List <file> allFiles, delta toApply) { List <file> candidates = allFiles.Where(x => x.size == toApply.sourceFileSize).ToList(); foreach (file candidate in candidates) { // todo } }
public void canStoreAndRetrieveWsusUpdates() { using (updateDB uut = new updateDB(connstr, testDBName, true)) { wsusUpdate testSourcefile = new wsusUpdate("http://foo.cab", new byte[] { 0x11, 0x22, 0x33 }, 112233); testSourcefile.dbID = 0xacab; uut.insertOrCreateWsusFile(testSourcefile); Assert.AreNotEqual(0xacab, testSourcefile); int?origID = testSourcefile.dbID; uut.insertOrCreateWsusFile(testSourcefile); Assert.AreNotEqual(0xacab, testSourcefile); Assert.AreEqual(origID, testSourcefile.dbID); } }
public void testLoggingOfCab() { using (updateDB uut = new updateDB(Program.connstr, Program.dbName, true)) { byte[] filehash = new byte[] { 0x3f, 0x06, 0x30, 0x72, 0x58, 0x2b, 0xd4, 0xae, 0xef, 0x41, 0xae, 0x19, 0xb0, 0x5d, 0xe5, 0x62, 0x43, 0x9c, 0x90, 0xeb }; wsusUpdate sourcefile = new wsusUpdate( "http://download.windowsupdate.com/d/msdownload/update/software/updt/2016/07/windows10.0-kb3161102-x86_3f063072582bd4aeef41ae19b05de562439c90eb.cab", filehash, 8406); uut.insert_noconcurrency(sourcefile); Program.Main(null); List <file> result = uut.getAllFiles(); List <string> errors = uut.getErrorStrings(); Assert.AreEqual(0, errors.Count); Assert.AreEqual(322, result.Count); // TODO: more tests! } }
public void canStoreAndRetrieveWIMEntries() { using (updateDB uut = new updateDB(connstr, testDBName, true)) { // Make files in two WIM images, coming from a single wsusupdat (ie, wim file). wsusUpdate testSourcefile = new wsusUpdate("http://foo.cab", new byte[] { 0xaa }, 1); uut.insert_noconcurrency(testSourcefile); testSourcefile = uut.getWSUSFileByFileHash(testSourcefile.fileHashFromWSUS); file_wimInfo fileA = new file_wimInfo("fileA", new byte[] { 0x01 }, new byte[] { 0xaa }, new fileSource_wim("test", 2, "descA", 10), "locA"); // These two files are both in the third imageindex. file_wimInfo fileB = new file_wimInfo("fileB", new byte[] { 0x02 }, new byte[] { 0xbb }, new fileSource_wim("foo", 3, "descB", 10), "locA"); file_wimInfo fileC = new file_wimInfo("fileC", new byte[] { 0x03 }, new byte[] { 0xcc }, new fileSource_wim("foo", 3, "descB", 10), "locA"); uut.bulkInsertFiles(testSourcefile, new file_wimInfo[] { fileA }); uut.bulkInsertFiles(testSourcefile, new file_wimInfo[] { fileB, fileC }); List <file_wimInfo> inDB = uut.getWimInfos(); Assert.AreEqual(3, inDB.Count); Assert.IsTrue(inDB.All(x => x.dbID.HasValue)); Assert.IsTrue(inDB.All(x => x.fileInfo.wsusFileID.HasValue)); Assert.IsTrue(inDB.All(x => x.fileInfo.wsusFileID.Value == testSourcefile.dbID)); file_wimInfo fromDB_A = inDB.FirstOrDefault(x => x.fileInfo.filename == "fileA"); file_wimInfo fromDB_B = inDB.FirstOrDefault(x => x.fileInfo.filename == "fileB"); file_wimInfo fromDB_C = inDB.FirstOrDefault(x => x.fileInfo.filename == "fileC"); Assert.IsNotNull(fromDB_A); Assert.IsNotNull(fromDB_B); Assert.IsNotNull(fromDB_C); Assert.AreEqual("descA", fromDB_A.parent.wimImageDescription); Assert.AreEqual("descB", fromDB_B.parent.wimImageDescription); Assert.AreEqual("descB", fromDB_C.parent.wimImageDescription); } }
public void canDedupeFilesInWIM() { using (updateDB uut = new updateDB(connstr, testDBName, true)) { wsusUpdate sourcefile = new wsusUpdate("http://foo.cab", new byte[] { 0x11, 0x22, 0x33 }, 123); uut.insert_noconcurrency(sourcefile); sourcefile = uut.getWSUSFileByFileHash(new byte[] { 0x11, 0x22, 0x33 }); fileSource_wim imageEntry = new fileSource_wim("test", 2, "abc", 10); file_wimInfo testFileA = new file_wimInfo("test file A", new byte[] { 0x11, 0x22, 0x33 }, new byte[] { 0xaa, 0xbb }, imageEntry, "loc1"); file_wimInfo testFileB = new file_wimInfo("test file B", new byte[] { 0x44, 0x55, 0x66 }, new byte[] { 0xcc, 0xdd }, imageEntry, "loc1"); uut.bulkInsertFiles(sourcefile, new file_wimInfo[] { testFileA }); uut.bulkInsertFiles(sourcefile, new file_wimInfo[] { testFileB }); // After a second insertion, no new rows should have been added. List <file_wimInfo> A = uut.getWimInfos(); uut.bulkInsertFiles(sourcefile, new file_wimInfo[] { testFileA }); uut.bulkInsertFiles(sourcefile, new file_wimInfo[] { testFileB }); List <file_wimInfo> B = uut.getWimInfos(); Assert.AreEqual(A.Count, B.Count); } }
public void canCreateDB() { using (updateDB uut = new updateDB(connstr, testDBName, true)) { } }