FindPackages() private method

private FindPackages ( ) : IIterable
return IIterable
示例#1
0
        private async static Task FindPackages() {
            PackageManager packageManager = new PackageManager();

            IEnumerable<Windows.ApplicationModel.Package> packages =
                (IEnumerable<Windows.ApplicationModel.Package>)packageManager.FindPackages();

            int packageCount = 0;
            foreach (var package in packages) {
                if (
                        (package.Id.Publisher.Contains("CN=Ron") || 
                        package.Id.Publisher.Contains("CN=Bob") || 
                        package.Id.FullName.StartsWith("Ron.")) 
                        && 
                        (!package.Id.FullName.StartsWith("Keep."))
                    )
                {
                    DisplayPackageInfo(package);
                    await packageManager.RemovePackageAsync(package.Id.FullName);
                    Console.WriteLine("=========================================================");
                }
                packageCount += 1;
            }

            if (packageCount < 1) {
                Console.WriteLine("No packages were found.");
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadLine();
        }
示例#2
0
        public bool DoesDependencyPackageExist(string packageName, Windows.System.ProcessorArchitecture architecture)
        {
            bool result   = false;
            var  packages = _packageManager.FindPackages().ToList();

            Windows.ApplicationModel.Package installedPackage = null;
            foreach (var pkg in packages)
            {
                if (string.Compare(pkg.Id.Name, packageName, true) == 0 && pkg.Id.Architecture == architecture)
                {
                    var fpkg = _packageManager.FindPackages(pkg.Id.Name, pkg.Id.Publisher).ToList();
                    installedPackage = fpkg.FirstOrDefault();
                    break;
                }
            }

            return(result = (installedPackage != null));
        }
    public static int Main(string[] args)
    {
        Console.WriteLine("Copyright (c) Microsoft Corporation. All rights reserved.");
        Console.WriteLine("FindPackagesByNameAndPublisher sample");
        Console.WriteLine();

        if (args.Length < 2)
        {
            Console.WriteLine("Usage: FindPackagesByNameAndPublisherSample.exe packageName publisherName");
            Console.WriteLine();

            return 1;
        }

        string inputPackageName = args[0];
        string inputPublisherName = args[1];

        Windows.Management.Deployment.PackageManager packageManager = new Windows.Management.Deployment.PackageManager();

        try
        {
            IEnumerable<Windows.ApplicationModel.Package> packages = (IEnumerable<Windows.ApplicationModel.Package>)packageManager.FindPackages(inputPackageName, inputPublisherName);

            int packageCount = 0;
            foreach (var package in packages)
            {
                DisplayPackageInfo(package);
                DisplayPackageUsers(packageManager, package);

                Console.WriteLine();
                packageCount += 1;
            }

            if (packageCount < 1)
            {
                Console.WriteLine("No packages were found.");
            }

        }
        catch (UnauthorizedAccessException)
        {
            Console.WriteLine("packageManager.FindPackages() failed because access was denied. This program must be run from an elevated command prompt.");

            return 1;
        }
        catch (Exception ex)
        {
            Console.WriteLine("packageManager.FindPackages() failed, error message: {0}", ex.Message);
            Console.WriteLine("Full Stacktrace: {0}", ex.ToString());

            return 1;
        }

        return 0;
    }
示例#4
0
    public AppInfo?GetAppInfoBySid(string sid)
    {
        AppInfo?info = null;

        AppInfosBySidLock.EnterReadLock();
        AppInfosBySid.TryGetValue(sid, out info);
        AppInfosBySidLock.ExitReadLock();
        if (info != null)
        {
            return(info);
        }

        string appPackageID = SidToAppPackage(sid);

        if (appPackageID == null || appPackageID.Length == 0)
        {
            return(null);
        }

        IEnumerable <Windows.ApplicationModel.Package> packages;

        try
        {
            packages = packageManager.FindPackages(appPackageID);
        }
        catch
        {
            return(null);
        }

        foreach (var package in packages)
        {
            info = GetInfo(package, sid);
            if (info != null)
            {
                AppInfosBySidLock.EnterWriteLock();
                if (!AppInfosBySid.ContainsKey(sid))
                {
                    AppInfosBySid.Add(sid, info);
                }
                AppInfosBySidLock.ExitWriteLock();
                break;
            }
        }

        return(info);
    }
示例#5
0
    public void LoadApps()
    {
        Apps.Clear();
        AppInfos.Clear();

        //packageManager.RemovePackageAsync(package.Id.FullName);

        IEnumerable <Windows.ApplicationModel.Package> packages = (IEnumerable <Windows.ApplicationModel.Package>)packageManager.FindPackages();

        // Todo: is there a better way to get this ?
        foreach (var package in packages)
        {
            string name;
            //string fullname;
            string path;
            string publisher;
            bool   isFramework;
            try
            {
                name = package.Id.Name;
                //fullname = package.Id.FullName;
                publisher   = package.Id.PublisherId;
                path        = package.InstalledLocation.Path;
                isFramework = package.IsFramework;
            }
            catch (Exception err)
            {
                AppLog.Line("Error in {0}: {1}", MiscFunc.GetCurrentMethod(), err.Message);
                continue;
            }

            string appPackageID = name.ToLower() + "_" + publisher;
            string appSID       = PackageIDToSid(appPackageID).ToLower();

            if (Apps.ContainsKey(package.InstalledLocation.Path.ToLower()))
            {
                AppLog.Line("Warning an app with the path: {0} is already listed", package.InstalledLocation.Path.ToLower());
            }
            else
            {
                Apps.Add(package.InstalledLocation.Path.ToLower(), appSID);
            }

            AppInfo?info = GetInfo(path, name, appPackageID, appSID);
            if (info != null)
            {
                AppInfo old_info;
                if (AppInfos.TryGetValue(appSID, out old_info))
                {
                    continue;
                }
                if (AppInfos.ContainsKey(appSID))
                {
                    AppLog.Line("Warning an app with the SID: {0} is already listed", appSID);
                }
                else
                {
                    AppInfos.Add(appSID, info.Value);
                }
            }
        }
    }
    public static int Main(string[] args)
    {
        Console.WriteLine("Copyright (c) Microsoft Corporation. All rights reserved.");
        Console.WriteLine("FindPackagesByNameAndPublisher sample");
        Console.WriteLine();

        if (args.Length < 2)
        {
            Console.WriteLine("Usage: FindPackagesByNameAndPublisherSample.exe packageName publisherName");
            Console.WriteLine();

            return(1);
        }

        string inputPackageName   = args[0];
        string inputPublisherName = args[1];

        Windows.Management.Deployment.PackageManager packageManager = new Windows.Management.Deployment.PackageManager();

        try
        {
            IEnumerable <Windows.ApplicationModel.Package> packages = (IEnumerable <Windows.ApplicationModel.Package>)packageManager.FindPackages(inputPackageName, inputPublisherName);

            int packageCount = 0;
            foreach (var package in packages)
            {
                DisplayPackageInfo(package);
                DisplayPackageUsers(packageManager, package);

                Console.WriteLine();
                packageCount += 1;
            }

            if (packageCount < 1)
            {
                Console.WriteLine("No packages were found.");
            }
        }
        catch (UnauthorizedAccessException)
        {
            Console.WriteLine("packageManager.FindPackages() failed because access was denied. This program must be run from an elevated command prompt.");

            return(1);
        }
        catch (Exception ex)
        {
            Console.WriteLine("packageManager.FindPackages() failed, error message: {0}", ex.Message);
            Console.WriteLine("Full Stacktrace: {0}", ex.ToString());

            return(1);
        }

        return(0);
    }