示例#1
0
        public static Package Deserialize(string url, string json, PackageList list)
        {
            var p = new Package();

            try
            {
                MemoryStream ms       = new MemoryStream(Encoding.UTF8.GetBytes(json));
                var          settings = new DataContractJsonSerializerSettings
                {
                    UseSimpleDictionaryFormat = true
                };

                var serializer = new DataContractJsonSerializer(typeof(Package), settings);
                p = serializer.ReadObject(ms) as Package;
                ms.Close();

                p.fileBlacklist      = p.fileBlacklist == null ? new string[0] : p.fileBlacklist;
                p.directoryBlacklist = p.directoryBlacklist == null ? new string[0] : p.directoryBlacklist;
                p.specialExtract     = p.specialExtract == null ? new Dictionary <string, string>(0) : p.specialExtract;
                p.requiresNexus      = p.RequiresNexusAPI();
                p.fileName           = Path.GetFileName(p.fileURL);
                p.url  = url;
                p.list = list;  //TODO

                return(p);
            }
            catch (System.Exception e)
            {
                Log.Write(e);
                return(GetErrorPackage(Path.GetFileName(url)));
            }
        }
示例#2
0
        private static void CleanUpTempFiles(PackageList list)
        {
            var destination = Path.Combine(Path.GetTempPath(), list.name);

            if (Directory.Exists(destination))
            {
                Directory.Delete(destination, true);
            }
        }
        private void PackageListUpdated(string path)
        {
            if (File.Exists(path))
            {
                packageList = PackageList.Deserialize(File.ReadAllText(path));
                if (packageList != null)
                {
                    packages = packageList.GetPackages();
                    if (packages != null)
                    {
                        packageListTitle.Text             = packageList.name;
                        packageListCurator.Text           = string.Format("Curated by: {0}", packageList.curator);
                        packageListDescription.Text       = packageList.description;
                        packageListUpdated.Text           = "Last updated:\n" + packageList.lastUpdated;
                        packagesView.ItemsSource          = packages;
                        packageListSuccessTick.Visibility = Visibility.Visible;
                        packageListRefresh.Visibility     = Visibility.Hidden;
                        installTab.IsEnabled = true;
                        CheckInstallability();
                        packageListInfo.Text = string.Empty;
                        return;
                    }
                    else
                    {
                        packageListRefresh.Visibility = Visibility.Visible;
                        packageListInfo.Text          = string.Format("{0} could not be deserialized due to bad package URLs. Double check the paths, or notify the curator.", Path.GetFileName(path));
                    }
                }
                else
                {
                    packageListRefresh.Visibility = Visibility.Visible;
                    packageListInfo.Text          = string.Format("{0} could not be deserialized due to malformed JSON. Check for corruption, or notify the curator.", Path.GetFileName(path));
                }
            }
            else
            {
                packageListRefresh.Visibility = Visibility.Hidden;
                packageListInfo.Text          = "Select a package list to install.";
            }

            // Path didn't exist, or the package list didn't deserialize properly.
            installTab.IsEnabled = false;
            packageListSuccessTick.Visibility = Visibility.Hidden;
            CheckInstallability();
        }
示例#4
0
        public static PackageList Deserialize(string json)
        {
            var p = new PackageList();

            try
            {
                MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json));

                var serializer = new DataContractJsonSerializer(typeof(PackageList));
                p = serializer.ReadObject(ms) as PackageList;
                ms.Close();
                return(p);
            }
            catch (System.Exception e)
            {
                Log.Write(e);
                return(null);
            }
        }