コード例 #1
0
ファイル: ProductManager.cs プロジェクト: forwolk/UnityApex
        internal static void ApplyPatches(ProductInfo p, ApexSettings settings)
        {
            var client = new WebClient
            {
                BaseAddress = EnsureTrailingSlash(settings.updateCheckBaseUrl)
            };

            client.Headers.Add("Accept", "application/xml");
            var request = string.Format("api/Products/GetAvailablePatches?productName={0}&version={1}", p.name, p.installedVersion);
            var patchList = client.DownloadString(request);

            var doc = XDocument.Parse(patchList);
            var ns = XNamespace.Get(doc.Root.Attribute("xmlns").Value);
            var patchFiles = from s in XDocument.Parse(patchList).Root.Elements(ns + "string")
                             select s.Value;

            foreach (var patchFile in patchFiles)
            {
                var patchPath = string.Concat(settings.dataFolder, "/", patchFile);
                var url = string.Concat("content/patches/", patchFile);
                client.DownloadFile(url, patchPath);

                AssetDatabase.ImportPackage(patchPath, false);
            }
        }
コード例 #2
0
        private void CreateProductEntry(ProductInfo p)
        {
            EditorGUILayout.BeginVertical("Box", GUILayout.Width(428));

            EditorGUILayout.BeginHorizontal();

            //Create and anchor the foldout
            GUILayout.Label(GUIContent.none, GUILayout.Width(230));

            var productLabel = new GUIContent(" " + p.name, p.icon);
            p.expanded = EditorGUI.Foldout(GUILayoutUtility.GetLastRect(), p.expanded, productLabel, true, _styles.foldout);

            //New update marker
            if (p.newUpdateAvailable)
            {
                if (p.status == ProductStatus.PatchAvailable)
                {
                    GUILayout.Label(new GUIContent("#", "New patch available!"), _styles.labelHighlight, GUILayout.Width(20));
                }
                else
                {
                    GUILayout.Label(new GUIContent("!", "New update available!"), _styles.labelHighlight, GUILayout.Width(20));
                }
            }
            else
            {
                GUILayout.Label(GUIContent.none, GUILayout.Width(20));
            }

            //Version
            GUIContent status;
            if (p.installedVersion == null)
            {
                status = new GUIContent("N/A", "Not installed");
            }
            else
            {
                status = new GUIContent(Write(p.installedVersion), "Installed version");
            }

            GUILayout.Label(status, GUILayout.Width(50));

            //Link buttons / status
            if (p.status != ProductStatus.UpToDate)
            {
                if (p.status == ProductStatus.ComingSoon)
                {
                    EditorGUILayout.LabelField("Coming soon", GUILayout.Width(80));
                }
                else if (p.status == ProductStatus.UpdateAvailable)
                {
                    if (GUILayout.Button(new GUIContent("Update It", string.Format("Version {0} is now available.\n\nClick to open the product's page on the Unity Asset Store.", p.newestVersion))))
                    {
                        AssetStore.Open(p.storeUrl);
                    }
                }
                else if (p.status == ProductStatus.ProductAvailable)
                {
                    if (GUILayout.Button(new GUIContent("Get It", "Now available.\n\nClick to open the product's page on the Unity Asset Store.")))
                    {
                        AssetStore.Open(p.storeUrl);
                    }
                }
                else if (p.status == ProductStatus.PatchAvailable)
                {
                    if (GUILayout.Button(new GUIContent("Patch It", "A patch is available.\n\nClick to download and apply the patch. Patches are hot fixes and all patches will be included in the following product update.")))
                    {
                        ProductManager.ApplyPatches(p, _settings);
                    }
                }
            }

            EditorGUILayout.EndHorizontal();

            //Details
            if (p.expanded)
            {
                GUILayout.Box(GUIContent.none, _styles.boxSeparator);
                var description = string.IsNullOrEmpty(p.description) ? "No description available" : p.description;
                EditorGUILayout.LabelField(description, _styles.labelWithWrap);

                EditorGUILayout.BeginHorizontal();

                if (!string.IsNullOrEmpty(p.productUrl))
                {
                    if (GUILayout.Button("Product Page", _styles.labelLink))
                    {
                        Application.OpenURL(p.productUrl);
                    }

                    EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
                }

                if (!string.IsNullOrEmpty(p.changeLogPath))
                {
                    if (GUILayout.Button("Change Log", _styles.labelLink))
                    {
                        Application.OpenURL(p.changeLogPath);
                    }

                    EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
                }

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndVertical();
        }
コード例 #3
0
ファイル: ProductManager.cs プロジェクト: andrewstarnes/wwtd2
        private static IEnumerable<ProductInfo> GetProductsInfo(ApexSettings settings, bool checkForUpdates)
        {
            var productsInfo = new List<ProductInfo>();

            //Get the currently installed products
            var installed = typeof(ProductManager).Assembly.GetCustomAttributes(typeof(ApexProductAttribute), true).Cast<ApexProductAttribute>();
            foreach (var p in installed)
            {
                var info = new ProductInfo
                {
                    name = p.name,
                    installedVersion = string.IsNullOrEmpty(p.version) ? null : new Version(p.version),
                    type = p.type
                };

                info.iconInfo = GetIconPath(settings, info);
                info.changeLogPath = GetChangeLogPath(settings, info);
                productsInfo.Add(info);
            }

            //Check existence of product manifest
            var manifestPath = string.Concat(settings.dataFolder, "/Products.manifest");
            bool checkedForUpdates = checkForUpdates || settings.timeToUpdate || (!File.Exists(manifestPath) && settings.allowAutomaticUpdateCheck);
            if (checkedForUpdates)
            {
                DownloadLatest(settings, manifestPath);
            }

            //Read the product manifest
            if (!File.Exists(manifestPath))
            {
                return productsInfo;
            }

            var installedLookup = productsInfo.ToDictionary(p => p.name, StringComparer.OrdinalIgnoreCase);

            try
            {
                var productsXml = XDocument.Load(manifestPath);
                XNamespace ns = productsXml.Root.Attribute("xmlns").Value;

                foreach (var p in productsXml.Root.Elements(ns + "Product"))
                {
                    var productName = p.Element(ns + "name").Value;

                    ProductInfo info;
                    if (!installedLookup.TryGetValue(productName, out info))
                    {
                        info = new ProductInfo();
                        productsInfo.Add(info);
                    }

                    var versionString = p.Element(ns + "version").Value;
                    var patchString = p.Element(ns + "latestPatch").Value;

                    info.name = productName;
                    info.description = p.Element(ns + "description").Value;
                    info.newestVersion = string.IsNullOrEmpty(versionString) ? null : new Version(versionString);
                    info.latestPatch = string.IsNullOrEmpty(patchString) ? null : new Version(patchString);
                    info.productUrl = p.Element(ns + "productUrl").Value;
                    info.storeUrl = p.Element(ns + "storeUrl").Value;
                    info.type = (ProductType)Enum.Parse(typeof(ProductType), p.Element(ns + "type").Value);
                    info.iconInfo = GetIconPath(settings, info);
                }
            }
            catch
            {
                //Just eat this, it should not happen, but if it does we do not want to impact the users, and there is no way to recover so...
            }

            //Apply update knowledge to list
            if (checkedForUpdates)
            {
                MarkPendingUpdates(settings, productsInfo);
                EnsureIcons(settings, productsInfo);
            }

            return productsInfo;
        }
コード例 #4
0
ファイル: ProductManager.cs プロジェクト: andrewstarnes/wwtd2
 internal static Texture GetIcon(ProductInfo p)
 {
     return GetIcon(p.iconInfo);
 }
コード例 #5
0
ファイル: ProductManager.cs プロジェクト: andrewstarnes/wwtd2
        private static string GetChangeLogPath(ApexSettings settings, ProductInfo p)
        {
            var subFolder = p.name;
            if (!subFolder.StartsWith("Apex "))
            {
                subFolder = string.Concat("Apex ", subFolder);
            }

            var path = string.Concat(settings.rootFolder, "/", subFolder, "/ChangeLog.txt");
            if (File.Exists(path))
            {
                return path;
            }

            return null;
        }
コード例 #6
0
ファイル: ProductManager.cs プロジェクト: andrewstarnes/wwtd2
 private static IconInfo GetIconPath(ApexSettings settings, ProductInfo p)
 {
     string key = (p.type == ProductType.Product) ? p.name.Replace(" ", string.Empty) : p.type.ToString();
     return new IconInfo
     {
         key = key,
         path = string.Concat(settings.relativeDataFolder, "/", key, ".png")
     };
 }
コード例 #7
0
ファイル: ProductManager.cs プロジェクト: Hengle/U3D_Demo
        private static IEnumerable <ProductInfo> GetProductsInfo(ApexSettings settings, bool checkForUpdates)
        {
            var productsInfo = new List <ProductInfo>();

            //Get the currently installed products
            var installed = typeof(ProductManager).Assembly.GetCustomAttributes(typeof(ApexProductAttribute), true).Cast <ApexProductAttribute>();

            foreach (var p in installed)
            {
                var info = new ProductInfo
                {
                    name             = p.name,
                    installedVersion = string.IsNullOrEmpty(p.version) ? null : new Version(p.version),
                    type             = p.type
                };

                info.iconInfo      = GetIconPath(settings, info);
                info.changeLogPath = GetChangeLogPath(settings, info);
                productsInfo.Add(info);
            }

            //Check existence of product manifest
            var  manifestPath      = string.Concat(settings.dataFolder, "/Products.manifest");
            bool checkedForUpdates = checkForUpdates || settings.timeToUpdate || (!File.Exists(manifestPath) && settings.allowAutomaticUpdateCheck);

            if (checkedForUpdates)
            {
                DownloadLatest(settings, manifestPath);
            }

            //Read the product manifest
            if (!File.Exists(manifestPath))
            {
                return(productsInfo);
            }

            var installedLookup = productsInfo.ToDictionary(p => p.name, StringComparer.OrdinalIgnoreCase);

            try
            {
                var        productsXml = XDocument.Load(manifestPath);
                XNamespace ns          = productsXml.Root.Attribute("xmlns").Value;

                foreach (var p in productsXml.Root.Elements(ns + "Product"))
                {
                    var productName = p.Element(ns + "name").Value;

                    ProductInfo info;
                    if (!installedLookup.TryGetValue(productName, out info))
                    {
                        info = new ProductInfo();
                        productsInfo.Add(info);
                    }

                    var versionString = p.Element(ns + "version").Value;
                    var patchString   = p.Element(ns + "latestPatch").Value;

                    info.name          = productName;
                    info.description   = p.Element(ns + "description").Value;
                    info.newestVersion = string.IsNullOrEmpty(versionString) ? null : new Version(versionString);
                    info.latestPatch   = string.IsNullOrEmpty(patchString) ? null : new Version(patchString);
                    info.productUrl    = p.Element(ns + "productUrl").Value;
                    info.storeUrl      = p.Element(ns + "storeUrl").Value;
                    info.type          = (ProductType)Enum.Parse(typeof(ProductType), p.Element(ns + "type").Value);
                    info.iconInfo      = GetIconPath(settings, info);
                }
            }
            catch
            {
                //Just eat this, it should not happen, but if it does we do not want to impact the users, and there is no way to recover so...
            }

            //Apply update knowledge to list
            if (checkedForUpdates)
            {
                MarkPendingUpdates(settings, productsInfo);
                EnsureIcons(settings, productsInfo);
            }

            return(productsInfo);
        }
コード例 #8
0
ファイル: ProductManager.cs プロジェクト: Hengle/U3D_Demo
 internal static Texture GetIcon(ProductInfo p)
 {
     return(GetIcon(p.iconInfo));
 }