コード例 #1
0
ファイル: UpdateMSU.cs プロジェクト: gilvbp/WinToolkit_v2
        public override Status Convert(string outDirectory)
        {
            Status = Status.Working;

            var extracted = Extraction.Expand(Location, "*.cab", _tempLocation);

            if (extracted)
            {
                if (MoveFromTemp(outDirectory, "*Windows*.cab"))
                {
                    return(Status.Success);
                }
            }
            return(Status.Failed);
        }
コード例 #2
0
        /// <summary>
        ///     Get package name and version.
        /// </summary>
        private void GetDetails()
        {
            Extraction.Expand(Location, "update.mum", _tempLocation);

            if (Directory.Exists(_tempLocation))
            {
                var msuInfo =
                    Directory.GetFiles(_tempLocation, "update.mum", SearchOption.TopDirectoryOnly).FirstOrDefault();

                if (msuInfo != null)
                {
                    var doc = new XmlDocument();
                    doc.Load(msuInfo);

                    var p = (XmlElement)doc.LastChild;
                    _packageDescription = p.Attributes["description"].InnerText;
                    _support            = p.Attributes["supportInformation"].InnerText;
                    if (p.HasAttribute("creationTimeStamp"))
                    {
                        _createdDate = DateTime.Parse(p.Attributes["creationTimeStamp"].InnerText);
                    }
                    else
                    {
                        _createdDate = FileHandling.GetModifiedDate(msuInfo);
                    }


                    var p2 = (XmlElement)p.ChildNodes[0];
                    _packageName = p2.Attributes["name"].InnerText;

                    _packageVersion = p2.Attributes["version"].InnerText;

                    var applies = _packageVersion.Split('.')[0] + "." + _packageVersion.Split('.')[1];
                    _appliesTo = applies;

                    _language = p2.Attributes["language"].InnerText;

                    var arc = p2.Attributes["processorArchitecture"].InnerText;
                    if (arc.EqualsIgnoreCase("amd64"))
                    {
                        _architecture = Architecture.X64;
                    }
                }
                FileHandling.DeleteDirectory(_tempLocation);
            }
        }
コード例 #3
0
ファイル: UpdateMSU.cs プロジェクト: gilvbp/WinToolkit_v2
        /// <summary>
        ///     Get package name and version.
        /// </summary>
        private void GetExtendedDetails()
        {
            Extraction.Expand(Location, "*.xml", _tempLocation);

            if (Directory.Exists(_tempLocation))
            {
                var msuInfo = Directory.GetFiles(_tempLocation, "*.xml", SearchOption.TopDirectoryOnly).FirstOrDefault();

                try
                {
                    if (msuInfo != null)
                    {
                        var xDoc = new XmlDocument();
                        xDoc.PreserveWhitespace = false;
                        xDoc.Load(msuInfo);

                        var xParent = xDoc.LastChild.LastChild.LastChild.FirstChild;

                        _packageName = xParent.Attributes["name"].InnerText;
                        _language    = xParent.Attributes["language"].InnerText;

                        var arc = xParent.Attributes["processorArchitecture"].InnerText;
                        if (arc.EqualsIgnoreCase("amd64"))
                        {
                            _architecture = Architecture.X64;
                        }

                        _packageVersion = xParent.Attributes["version"].InnerText;
                        var appliesTo = _packageVersion.Split('.')[0] + "." + _packageVersion.Split('.')[1];
                        _appliesTo = appliesTo;
                    }
                }
                catch (Exception Ex)
                {
                    FileHandling.WriteFile("Errors.txt", Ex.Message + "\r\n", true);
                }
                FileHandling.DeleteDirectory(_tempLocation);
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: gilvbp/WinToolkit_v2
        private static void Main(string[] args)
        {
            Cleanup();

            try
            {
                Console.WindowHeight = 50;
            }
            catch
            {
            }

            if (args.Length == 0)
            {
                WriteText("No directory specified", ConsoleColor.Red);
                return;
            }

            var files    = new List <string>();
            var foundDir = new List <UpdateDirectory>();

            WriteText("Deleting [" + UpdateCache.CACHE_PATH_XML + "]...", ConsoleColor.Yellow);
            FileHandling.DeleteFile(UpdateCache.CACHE_PATH_XML);

            WriteText("Deleting [" + UpdateCache.CACHE_ERROR_XML + "]...", ConsoleColor.Yellow);
            FileHandling.DeleteFile(UpdateCache.CACHE_ERROR_XML);
            Console.WriteLine();

            foreach (var directory in args.AsParallel())
            {
                try
                {
                    if (!Directory.Exists(directory))
                    {
                        WriteText("Invalid directory [" + directory + "]", ConsoleColor.Red);
                        return;
                    }
                    WriteText("Searching [" + directory + "]...", ConsoleColor.Yellow);

                    var foundFiles = Directory.GetFileSystemEntries(directory, "*.*", SearchOption.AllDirectories)
                                     .Where(
                        f =>
                        Path.GetExtension(f)
                        .EndsWithIgnoreCase(".MSU", StringComparison.InvariantCultureIgnoreCase) ||
                        Path.GetExtension(f)
                        .EndsWithIgnoreCase(".CAB", StringComparison.InvariantCultureIgnoreCase))
                                     .ToArray();

                    lock (files)
                    {
                        var updDirectory = new UpdateDirectory
                        {
                            Path      = directory,
                            FileCount = foundFiles.Length
                        };

                        foundDir.Add(updDirectory);
                        files.AddRange(foundFiles);
                    }
                }
                catch (Exception Ex)
                {
                    Console.WriteLine(Ex.Message);
                    Console.ReadKey();
                }
            }


            Console.Title  = "Building Update Cache";
            Options.GetMD5 = true;
            WriteText("Found " + files.Count + " files.");

            WriteText("Loading Cache...");
            UpdateCache.Load();

            var i     = 1;
            var Cache = UpdateCache.Count;
            var total = files.Count;

            foreach (var update in files)
            {
                Console.Clear();
                var progress = ((float)i / total);
                WriteText("Building Cache " + i + " of " + total + " [" + progress.ToString("0.00%") + "]",
                          ConsoleColor.Cyan);
                Console.WriteLine();
                foreach (var updDirectory in foundDir)
                {
                    WriteText(" [" + updDirectory.Path + "] :: " + updDirectory.FileCount);
                }

                Console.WriteLine();
                WriteText("Cache: " + Cache);
                WriteText("Total: " + UpdateCache.Count + " | New: " +
                          (UpdateCache.Count - Cache - UpdateCache.UnknownCount));
                Console.WriteLine();

                WriteText("GDR: " + UpdateCache.GDRCount);
                WriteText("LDR: " + UpdateCache.LDRCount);
                WriteText("Unknown: " + UpdateCache.UnknownCount);
                Console.WriteLine();
                WriteText("----------------------------------------");
                Console.WriteLine();
                string cabFile;
                var    temp = Directories.Application + "\\Temp\\" + i;

                MsuUpdate msuItem = null;
                WriteText("Name: " + Path.GetFileName(update));
                WriteText("Size: " + FileHandling.GetSize(update, true));
                Console.WriteLine();
                if (update.EndsWithIgnoreCase("MSU", StringComparison.InvariantCultureIgnoreCase))
                {
                    WriteText("Checking MSU [" + update + "]");
                    if (UpdateCache.Find(Path.GetFileName(update), FileHandling.GetSize(update)) != null)
                    {
                        i++;
                        continue;
                    }

                    WriteText("Preparing MSU [" + update + "]");
                    msuItem = new MsuUpdate(update);

                    WriteText("Extracting CAB [" + update + "]");
                    Extraction.Expand(update, "*.cab", temp);

                    cabFile = Directory.GetFiles(temp, "*.cab", SearchOption.TopDirectoryOnly).FirstOrDefault();

                    if (cabFile == null)
                    {
                        msuItem.UpdateType = UpdateType.GDR;
                        UpdateCache.Add(msuItem);
                    }
                }
                else
                {
                    cabFile = update;
                }

                if (!string.IsNullOrWhiteSpace(cabFile))
                {
                    if (msuItem != null)
                    {
                        Console.WriteLine();
                    }

                    WriteText("Checking CAB [" + update + "]");
                    if (UpdateCache.Find(Path.GetFileName(cabFile), FileHandling.GetSize(cabFile)) == null)
                    {
                        WriteText("Preparing CAB [" + cabFile + "]");
                        var cabItem = new CabUpdate(cabFile);

                        WriteText("Extracting CAB Files [" + cabFile + "]");
                        Extraction.Expand(cabFile, "update-bf.mum", temp);

                        cabItem.UpdateType = UpdateType.GDR;

                        if (File.Exists(temp + "\\update-bf.mum"))
                        {
                            cabItem.UpdateType = UpdateType.LDR;
                        }
                        Console.WriteLine();
                        WriteText("Update is " + cabItem.UpdateType, ConsoleColor.Green);
                        UpdateCache.Add(cabItem);
                        if (msuItem != null)
                        {
                            msuItem.UpdateType = cabItem.UpdateType;
                            UpdateCache.Add(msuItem);
                        }
                    }
                }

                FileHandling.DeleteDirectory(temp);
                i++;
            }
            Cleanup();

            Console.WriteLine();
            WriteText("Build complete. Press any key to close.", ConsoleColor.Green);
            Console.ReadKey();
        }
コード例 #5
0
ファイル: UpdateMSU.cs プロジェクト: gilvbp/WinToolkit_v2
        /// <summary>
        ///     Either installs or integrate the update to the live OS or image.
        /// </summary>
        /// <param name="LDR">Install LDR or GDR.</param>
        /// <returns></returns>
        private Status DoWork(Task task, string mountPath, bool LDR)
        {
            if (_progressBar == null)
            {
                _progressBar = new ProgressBar();
            }

            _progressBar.Value = 0;

            Status = Status.Working;

            if (CheckIntegration(mountPath, LDR))
            {
                return(Status.Success);
            }

            if (task == Task.Install)
            {
                Processes.Run("wusa.exe", "\"" + Location + "\" /quiet /norestart");
            }
            else
            {
                Processes.Run(DISM.Default.Location,
                              "/Image:\"" + mountPath + "\" /Add-Package /Packagepath:\"" + Location + "\"");
            }

            if (LDR && (_updateType == UpdateType.Unknown || _updateType == UpdateType.LDR))
            {
                if (CheckIntegration(mountPath))
                {
                    return(Status.Failed);
                }
                Extraction.Expand(Location, "*.cab", _tempLocation);

                var cabFile = Directory.GetFiles(_tempLocation, "*.cab", SearchOption.TopDirectoryOnly).First();
                Extraction.Expand(cabFile, _tempLocation);

                _updateType = UpdateType.GDR;
                if (File.Exists(_tempLocation + "\\update-bf.mum"))
                {
                    _updateType = UpdateType.LDR;

                    if (task == Task.Install)
                    {
                        Processes.Run("pkgmgr.exe",
                                      "/ip /m:\"" + _tempLocation + "\\update-bf.mum" + "\" /quiet /norestart");
                    }
                    else
                    {
                        var s = Processes.Run("DISM",
                                              "/Image:\"" + mountPath + "\" /Add-Package /Packagepath:\"" + _tempLocation +
                                              "\\update-bf.mum" + "\"");
                        MessageBox.Show(s);
                    }
                }

                FileHandling.DeleteDirectory(_tempLocation);
            }

            UpdateCache.Add(this);

            if (_updateType != UpdateType.LDR)
            {
                LDR = false;
            }

            if (CheckIntegration(mountPath, LDR))
            {
                return(Status.Success);
            }
            return(Status.Failed);
        }
コード例 #6
0
ファイル: UpdateMSU.cs プロジェクト: gilvbp/WinToolkit_v2
        /// <summary>
        ///     Create a new MSU Update object with
        ///     only basic information.
        /// </summary>
        /// <param name="filePath">MSU file path.</param>
        public MsuUpdate(string filePath)
            : base(filePath)
        {
            if (!File.Exists(Location))
            {
                throw new FileNotFoundException();
            }
            if (!Location.EndsWithIgnoreCase(".MSU"))
            {
                throw new InvalidOperationException("This is not a msu file.");
            }

            switch (_updateType)
            {
            case UpdateType.LDR:
                _image = "/Images/_Global/MSUUpdateLDR_32.png";
                break;

            case UpdateType.GDR:
                _image = "/Images/_Global/MSUUpdateGDR_32.png";
                break;

            default:
                _image = "/Images/_Global/MSUUpdate_32.png";
                break;
            }

            if (!string.IsNullOrWhiteSpace(_packageName))
            {
                return;
            }

            Extraction.Expand(Location, "*.msu", _tempLocation);

            GetBasicDetails();
            GetExtendedDetails();

            if (_packageName == null)
            {
                Extraction.Expand(Location, "*.cab", _tempLocation);
                var cabFile = Directory.GetFiles(_tempLocation, "*.cab", SearchOption.TopDirectoryOnly).FirstOrDefault();

                if (cabFile != null)
                {
                    var cab = new CabUpdate(cabFile);
                    _packageName        = cab.PackageName;
                    _updateType         = cab.UpdateType;
                    _packageVersion     = cab.PackageVersion;
                    _packageDescription = cab.Description;
                    _appliesTo          = cab.AppliesTo;
                    _architecture       = cab.Architecture;
                    _createdDate        = cab.Date;
                    _language           = cab.Language;
                    _support            = cab.Support;
                    return;
                }
            }


            if (_packageName == null)
            {
                throw new InvalidDataException("Invalid Update");
            }
        }
コード例 #7
0
ファイル: UpdateMSU.cs プロジェクト: gilvbp/WinToolkit_v2
        /// <summary>
        ///     Get support link, architecture, description, language, and date.
        /// </summary>
        private void GetBasicDetails()
        {
            Extraction.Expand(Location, "*Windows*pkgProperties.txt", _tempLocation);

            if (Directory.Exists(_tempLocation))
            {
                var msuInfo = Directory.GetFiles(_tempLocation, "*.txt", SearchOption.TopDirectoryOnly).FirstOrDefault();

                if (msuInfo != null)
                {
                    var msuText = FileHandling.ReadFile(msuInfo);


                    foreach (var lines in msuText.Split(Environment.NewLine.ToCharArray()))
                    {
                        var line = lines.Trim();
                        if (string.IsNullOrWhiteSpace(line))
                        {
                            continue;
                        }

                        if (line.StartsWithIgnoreCase("Applies to="))
                        {
                            var applyTo = line.Replace("\"", "");
                            //if (applyTo.EndsWithIgnoreCase("Windows Blue"))
                            //{
                            //    _appliesTo = 6.3m;
                            //}
                            //else
                            //{
                            //    _appliesTo = decimal.Parse(applyTo.Substring(applyTo.Length - 3));
                            //}
                        }
                        if (line.StartsWithIgnoreCase("Build Date="))
                        {
                            _createdDate = DateTime.Parse(line.Split('=').Last().Replace("\"", ""));
                        }
                        if (line.StartsWithIgnoreCase("Language="))
                        {
                            _language = line.Split('=').Last().Replace("\"", "");
                        }
                        if (line.StartsWithIgnoreCase("Package Type="))
                        {
                            _packageDescription = line.Split('=').Last().Replace("\"", "");
                        }
                        if (line.StartsWithIgnoreCase("Support Link="))
                        {
                            _support = line.Substring(13).Replace("\"", "");
                        }

                        if (line.StartsWithIgnoreCase("Processor Architecture="))
                        {
                            if (line.Split('=').Last().ContainsIgnoreCase("amd64"))
                            {
                                _architecture = Architecture.X64;
                            }
                        }
                    }
                }

                FileHandling.DeleteDirectory(_tempLocation);
            }
        }
コード例 #8
0
        /// <summary>
        ///     Either installs or integrate the update to the live OS or image.
        /// </summary>
        /// <param name="LDR">Install LDR or GDR.</param>
        /// <returns></returns>
        private Status DoWork(Task task, string mountPath, bool LDR)
        {
            if (_progressBar == null)
            {
                _progressBar = new ProgressBar();
            }

            _progressBar.Value = 0;

            Status = Status.Working;

            // if (CheckIntegration(mountPath, LDR)) { return Status.Success; }

            if (task == Task.Install)
            {
                using (var session = DismApi.OpenOnlineSession())
                {
                    DismApi.AddPackage(session, Location, true, false,
                                       delegate(DismProgress progress) { _progressBar.Value = progress.Current; });
                }
                // Processes.Run("pkgmgr.exe", "/ip /m:\"" + Location + "\" /quiet /norestart");
            }
            else
            {
                Processes.Run(DISM.Default.Location,
                              "/Image:\"" + mountPath + "\" /Add-Package /Packagepath:\"" + Location + "\"");
            }

            if (LDR && (_updateType == UpdateType.Unknown || _updateType == UpdateType.LDR))
            {
                if (CheckIntegration(mountPath))
                {
                    return(Status.Failed);
                }
                Extraction.Expand(Location, _tempLocation);

                _updateType = UpdateType.GDR;
                if (File.Exists(_tempLocation + "\\update-bf.mum"))
                {
                    _updateType = UpdateType.LDR;

                    if (task == Task.Install)
                    {
                        Processes.Run("pkgmgr.exe",
                                      "/ip /m:\"" + _tempLocation + "\\update-bf.mum" + "\" /quiet /norestart");
                    }
                    else
                    {
                        var s = Processes.Run("DISM",
                                              "/Image:\"" + mountPath + "\" /Add-Package /Packagepath:\"" + _tempLocation +
                                              "\\update-bf.mum" + "\"");
                        MessageBox.Show(s);
                    }
                }

                FileHandling.DeleteDirectory(_tempLocation);
            }

            UpdateCache.Add(this);

            if (_updateType != UpdateType.LDR)
            {
                LDR = false;
            }

            if (CheckIntegration(mountPath, LDR))
            {
                return(Status.Success);
            }
            return(Status.Failed);
        }