Esempio n. 1
0
        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.generalName, 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);
            }
        }
Esempio n. 2
0
        internal static void EnsureIcons(ApexSettings settings, IEnumerable<ProductInfo> products)
        {
            foreach (var p in products)
            {
                if (_iconTextures.ContainsKey(p.iconInfo.key))
                {
                    continue;
                }

                string fileLocation = string.Concat(settings.dataFolder, "/", p.iconInfo.key, ".png");
                if (!File.Exists(fileLocation))
                {
                    try
                    {
                        var client = new WebClient
                        {
                            BaseAddress = EnsureTrailingSlash(settings.updateCheckBaseUrl)
                        };

                        string webLocationIcon = string.Concat("content/producticons/", p.iconInfo.key, ".png");
                        client.DownloadFile(webLocationIcon, fileLocation);

                        fileLocation = string.Concat(fileLocation, ".meta");
                        string webLocationMeta = string.Concat(webLocationIcon, ".meta");
                        client.DownloadFile(webLocationMeta, fileLocation);

                        _assetsDownloaded = true;
                    }
                    catch
                    {
                        /* not much to do about it.. */
                    }
                }
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        internal static void EnsureIcons(ApexSettings settings, IEnumerable <ProductInfo> products)
        {
            foreach (var p in products)
            {
                if (_iconTextures.ContainsKey(p.iconInfo.key))
                {
                    continue;
                }

                string fileLocation = string.Concat(settings.dataFolder, "/", p.iconInfo.key, ".png");
                if (!File.Exists(fileLocation))
                {
                    try
                    {
                        var client = new WebClient
                        {
                            BaseAddress = EnsureTrailingSlash(settings.updateCheckBaseUrl)
                        };

                        string webLocationIcon = string.Concat("content/producticons/", p.iconInfo.key, ".png");
                        client.DownloadFile(webLocationIcon, fileLocation);

                        fileLocation = string.Concat(fileLocation, ".meta");
                        string webLocationMeta = string.Concat(webLocationIcon, ".meta");
                        client.DownloadFile(webLocationMeta, fileLocation);

                        _assetsDownloaded = true;
                    }
                    catch
                    {
                        /* not much to do about it.. */
                    }
                }
            }
        }
        internal static bool TryGetSettings(out ApexSettings settings)
        {
            if (_instance != null)
            {
                settings = _instance;
                return(true);
            }

            var    apexRoot           = AssetPath.GetApexRoot(false);
            var    dataFolder         = AssetPath.GetApexDataFolder(false);
            var    relativeDataFolder = AssetPath.GetApexDataFolder(true);
            string settingsPath       = AssetPath.Combine(relativeDataFolder, "ApexSettings.asset");

            AssetPath.EnsurePath(relativeDataFolder);

            _instance = AssetDatabase.LoadAssetAtPath(settingsPath, typeof(ApexSettings)) as ApexSettings;

            bool settingsFound = (_instance != null);

            if (!settingsFound)
            {
                _instance = ScriptableObject.CreateInstance <ApexSettings>();

                AssetDatabase.CreateAsset(_instance, settingsPath);
                AssetDatabase.SaveAssets();
            }

            _instance.rootFolder         = apexRoot;
            _instance.dataFolder         = dataFolder;
            _instance.relativeDataFolder = relativeDataFolder;
            settings = _instance;
            return(settingsFound);
        }
Esempio n. 6
0
        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")
            });
        }
Esempio n. 7
0
        internal static void GetProductsInfoAsync(ApexSettings settings, bool checkForUpdates, Action <IEnumerable <ProductInfo> > callback)
        {
            EditorAsync.Execute(
                () => GetProductsInfo(settings, checkForUpdates),
                products =>
            {
                if (settings.isDirty)
                {
                    settings.SaveChanges();
                }

                callback(products);
            });
        }
Esempio n. 8
0
        private static string GetChangeLogPath(ApexSettings settings, ProductInfo p)
        {
            var subFolder = p.generalName;

            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);
        }
Esempio n. 9
0
        internal static void GetProductsInfoAsync(ApexSettings settings, bool checkForUpdates, Action <IEnumerable <ProductInfo> > callback)
        {
            EditorAsync.Execute(
                () => GetProductsInfo(settings, checkForUpdates),
                products =>
            {
                if (settings.isDirty)
                {
                    settings.SaveChanges();
                }

                if (_assetsDownloaded)
                {
                    _assetsDownloaded = false;
                    AssetDatabase.Refresh();
                }

                callback(products);
            });
        }
Esempio n. 10
0
        internal static void GetProductsInfoAsync(ApexSettings settings, bool checkForUpdates, Action<IEnumerable<ProductInfo>> callback)
        {
            EditorAsync.Execute(
                () => GetProductsInfo(settings, checkForUpdates),
                products =>
                {
                    if (settings.isDirty)
                    {
                        settings.SaveChanges();
                    }

                    if (_assetsDownloaded)
                    {
                        _assetsDownloaded = false;
                        AssetDatabase.Refresh();
                    }

                    callback(products);
                });
        }
Esempio n. 11
0
        private static void MarkPendingUpdates(ApexSettings settings, IEnumerable <ProductInfo> products)
        {
            var knownPending = settings.GetKnownPendingUpdates();
            var newPending   = new List <string>();

            foreach (var p in products)
            {
                if (p.status == ProductStatus.UpToDate || p.status == ProductStatus.ComingSoon)
                {
                    continue;
                }

                //For updates we alert when a new version arrives, even if the previous version was not yet updated to
                //For new products we only alert once
                string key = (p.status == ProductStatus.UpdateAvailable) ? string.Concat(p.generalName, "@", p.newestVersion) : p.generalName;
                newPending.Add(key);

                p.newUpdateAvailable = !knownPending.Contains(key);
            }

            settings.UpdateKnowPendingUpdates(newPending.ToArray());
        }
Esempio n. 12
0
        private static void DownloadLatest(ApexSettings settings, string manifestPath)
        {
            var client = new WebClient
            {
                BaseAddress = EnsureTrailingSlash(settings.updateCheckBaseUrl)
            };

            string serviceUrl = null;

            try
            {
                client.Headers.Add("Accept", "application/xml");
                var latestUpdate = XmlSingleValue(client.DownloadString("api/Service/GetLatestUpdateTime"));

                if (settings.lastUpdateCheck >= DateTime.Parse(latestUpdate, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal))
                {
                    settings.UpdateCompleted(null);
                    return;
                }

                client.Headers.Add("Accept", "application/xml");
                var productManifest = client.DownloadString("api/Products/GetProducts");
                using (var w = new StreamWriter(manifestPath))
                {
                    w.Write(productManifest);
                }

                client.Headers.Add("Accept", "application/xml");
                serviceUrl = XmlSingleValue(client.DownloadString("api/Service/GetServiceUrl"));
            }
            catch
            {
                return;
            }

            settings.UpdateCompleted(serviceUrl);
        }
Esempio n. 13
0
        private static IEnumerable <ProductInfo> GetProductsInfo(ApexSettings settings, bool checkForUpdates)
        {
            var productsInfo = new List <ProductInfo>();

            //Get the currently installed products
            var installed = from a in AppDomain.CurrentDomain.GetAssemblies()
                            from attrib in a.GetCustomAttributes(typeof(ApexProductAttribute), true).Cast <ApexProductAttribute>()
                            select attrib;

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

                info.icon          = GetIcon(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.generalName, 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);
                        info.name = info.generalName = productName;
                    }

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

                    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.icon          = GetIcon(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);
            }

            return(productsInfo);
        }
Esempio n. 14
0
 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")
     };
 }
Esempio n. 15
0
        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;
        }
Esempio n. 16
0
        private static void MarkPendingUpdates(ApexSettings settings, IEnumerable<ProductInfo> products)
        {
            var knownPending = settings.GetKnownPendingUpdates();
            var newPending = new List<string>();

            foreach (var p in products)
            {
                if (p.status == ProductStatus.UpToDate || p.status == ProductStatus.ComingSoon)
                {
                    continue;
                }

                //For updates we alert when a new version arrives, even if the previous version was not yet updated to
                //For new products we only alert once
                string key = (p.status == ProductStatus.UpdateAvailable) ? string.Concat(p.name, "@", p.newestVersion) : p.name;
                newPending.Add(key);

                p.newUpdateAvailable = !knownPending.Contains(key);
            }

            settings.UpdateKnowPendingUpdates(newPending.ToArray());
        }
Esempio n. 17
0
        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;
        }
        internal static bool TryGetSettings(out ApexSettings settings)
        {
            if (_instance != null)
            {
                settings = _instance;
                return true;
            }

            string assetsFolder = Application.dataPath;

            var locations = Directory.GetFiles(assetsFolder, typeof(ApexSettings).Name + ".cs", SearchOption.AllDirectories);
            if (locations.Length != 1)
            {
                settings = null;
                return false;
            }

            var tmp = Path.GetDirectoryName(locations[0]);
            var apexRoot = NormalizePath(tmp.Substring(0, tmp.LastIndexOf("Apex Path", StringComparison.OrdinalIgnoreCase)));
            var dataFolder = CombinePath(apexRoot, "Editor/Data");
            var relativeDataFolder = dataFolder.Substring(dataFolder.IndexOf("Assets", StringComparison.OrdinalIgnoreCase));
            string settingsPath = CombinePath(relativeDataFolder, "ApexSettings.asset");

            if (string.IsNullOrEmpty(AssetDatabase.AssetPathToGUID(relativeDataFolder)))
            {
                var subhierarchy = relativeDataFolder.Split('/');
                var parent = subhierarchy[0];
                for (int i = 1; i < subhierarchy.Length; i++)
                {
                    var subFolder = subhierarchy[i];
                    var subPath = CombinePath(parent, subFolder);
                    if (string.IsNullOrEmpty(AssetDatabase.AssetPathToGUID(subPath)))
                    {
                        AssetDatabase.CreateFolder(parent, subFolder);
                    }

                    parent = subPath;
                }
            }
            else
            {
#if UNITY_5
                _instance = AssetDatabase.LoadAssetAtPath<ApexSettings>(settingsPath);
#else
                _instance = Resources.LoadAssetAtPath<ApexSettings>(settingsPath);
#endif

                if (_instance != null)
                {
                    _instance.rootFolder = apexRoot;
                    _instance.dataFolder = dataFolder;
                    _instance.relativeDataFolder = relativeDataFolder;
                    settings = _instance;
                    return true;
                }
            }

            //No settings found so create some
            _instance = ScriptableObject.CreateInstance<ApexSettings>();

            AssetDatabase.CreateAsset(_instance, settingsPath);
            AssetDatabase.SaveAssets();

            _instance.rootFolder = apexRoot;
            _instance.dataFolder = dataFolder;
            _instance.relativeDataFolder = relativeDataFolder;
            settings = _instance;
            return false;
        }
Esempio n. 19
0
        internal static bool TryGetSettings(out ApexSettings settings)
        {
            if (_instance != null)
            {
                settings = _instance;
                return(true);
            }

            string assetsFolder = Application.dataPath;

            var locations = Directory.GetFiles(assetsFolder, typeof(ApexSettings).Name + ".cs", SearchOption.AllDirectories);

            if (locations.Length != 1)
            {
                settings = null;
                return(false);
            }

            var    tmp                = Path.GetDirectoryName(locations[0]);
            var    apexRoot           = NormalizePath(tmp.Substring(0, tmp.LastIndexOf("Apex Path", StringComparison.OrdinalIgnoreCase)));
            var    dataFolder         = CombinePath(apexRoot, "Editor/Data");
            var    relativeDataFolder = dataFolder.Substring(dataFolder.IndexOf("Assets", StringComparison.OrdinalIgnoreCase));
            string settingsPath       = CombinePath(relativeDataFolder, "ApexSettings.asset");

            if (string.IsNullOrEmpty(AssetDatabase.AssetPathToGUID(relativeDataFolder)))
            {
                var subhierarchy = relativeDataFolder.Split('/');
                var parent       = subhierarchy[0];
                for (int i = 1; i < subhierarchy.Length; i++)
                {
                    var subFolder = subhierarchy[i];
                    var subPath   = CombinePath(parent, subFolder);
                    if (string.IsNullOrEmpty(AssetDatabase.AssetPathToGUID(subPath)))
                    {
                        AssetDatabase.CreateFolder(parent, subFolder);
                    }

                    parent = subPath;
                }
            }
            else
            {
#if UNITY_5
                _instance = AssetDatabase.LoadAssetAtPath <ApexSettings>(settingsPath);
#else
                _instance = Resources.LoadAssetAtPath <ApexSettings>(settingsPath);
#endif

                if (_instance != null)
                {
                    _instance.rootFolder         = apexRoot;
                    _instance.dataFolder         = dataFolder;
                    _instance.relativeDataFolder = relativeDataFolder;
                    settings = _instance;
                    return(true);
                }
            }

            //No settings found so create some
            _instance = ScriptableObject.CreateInstance <ApexSettings>();

            AssetDatabase.CreateAsset(_instance, settingsPath);
            AssetDatabase.SaveAssets();

            _instance.rootFolder         = apexRoot;
            _instance.dataFolder         = dataFolder;
            _instance.relativeDataFolder = relativeDataFolder;
            settings = _instance;
            return(false);
        }
Esempio n. 20
0
        private static void DownloadLatest(ApexSettings settings, string manifestPath)
        {
            var client = new WebClient
            {
                BaseAddress = EnsureTrailingSlash(settings.updateCheckBaseUrl)
            };

            string serviceUrl = null;

            try
            {
                client.Headers.Add("Accept", "application/xml");
                var latestUpdate = XmlSingleValue(client.DownloadString("api/Service/GetLatestUpdateTime"));

                if (settings.lastUpdateCheck >= DateTime.Parse(latestUpdate, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal))
                {
                    settings.UpdateCompleted(null);
                    return;
                }

                client.Headers.Add("Accept", "application/xml");
                var productManifest = client.DownloadString("api/Products/GetProducts");
                using (var w = new StreamWriter(manifestPath))
                {
                    w.Write(productManifest);
                }

                client.Headers.Add("Accept", "application/xml");
                serviceUrl = XmlSingleValue(client.DownloadString("api/Service/GetServiceUrl"));
            }
            catch
            {
                return;
            }

            settings.UpdateCompleted(serviceUrl);
        }