Пример #1
0
        /// <summary>
        /// Remove package files
        /// </summary>
        /// <param name="pkgId">Package Id</param>
        public static void UninstallPackage(string pkgId)
        {
            var installedFiles = BlogService.InstalledFromGalleryPackageFiles(pkgId);

            if (installedFiles.Count == 0)
            {
                Utils.Log($"Can not find any files installed for package: {pkgId}");
                throw new ApplicationException("No files to uninstall");
            }

            var repo = new BlogEngine.Core.Data.PackageRepository();
            var pkg  = repo.FindById(pkgId);

            foreach (var file in installedFiles.OrderByDescending(f => f.FileOrder))
            {
                var fullPath = HttpContext.Current.Server.MapPath(Path.Combine(Utils.RelativeWebRoot, file.FilePath));

                if (file.IsDirectory)
                {
                    var folder = new DirectoryInfo(fullPath);
                    if (folder.Exists)
                    {
                        try
                        {
                            Directory.Delete(fullPath, true);
                        }
                        catch (Exception)
                        {
                            // this is to fix locking issue that
                            // sometimes happens in recursive deletes
                            System.Threading.Thread.Sleep(1);
                            try
                            {
                                Directory.Delete(fullPath, true);
                            }
                            catch (Exception ex)
                            {
                                Utils.Log("Error deleting directory " + fullPath + "; " + ex.Message);
                            }
                        }
                    }
                }
                else if (File.Exists(fullPath))
                {
                    File.Delete(fullPath);
                }
            }

            if (pkg != null && !string.IsNullOrWhiteSpace(pkg.OnlineVersion))
            {
                var pkgDir = $"{pkgId}.{pkg.OnlineVersion}";

                // clean up removing installed version
                pkgDir = HttpContext.Current.Server.MapPath($"{Utils.ApplicationRelativeWebRoot}App_Data/packages/{pkgDir}");
                if (Directory.Exists(pkgDir))
                {
                    ForceDeleteDirectory(pkgDir);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Remove package files
        /// </summary>
        /// <param name="pkgId">Package Id</param>
        public static void UninstallPackage(string pkgId)
        {
            var installedFiles = BlogService.InstalledFromGalleryPackageFiles(pkgId);

            if (installedFiles.Count == 0)
            {
                Utils.Log(string.Format("Can not find any files installed for package: {0}", pkgId));
                throw new ApplicationException("No files to uninstall");
            }

            var repo = new BlogEngine.Core.Data.PackageRepository();
            var pkg  = repo.FindById(pkgId);

            foreach (var file in installedFiles.OrderByDescending(f => f.FileOrder))
            {
                var fullPath = HttpContext.Current.Server.MapPath(Path.Combine(Utils.RelativeWebRoot, file.FilePath));

                if (file.IsDirectory)
                {
                    var folder = new DirectoryInfo(fullPath);
                    if (folder.Exists)
                    {
                        if (folder.GetFileSystemInfos().Length == 0)
                        {
                            ForceDeleteDirectory(fullPath);
                        }
                        else
                        {
                            Utils.Log(string.Format("Package Uninstaller: can not remove directory if it is not empty ({0})", fullPath));
                        }
                    }
                }
                else if (File.Exists(fullPath))
                {
                    File.Delete(fullPath);
                }
            }

            if (pkg != null && !string.IsNullOrWhiteSpace(pkg.OnlineVersion))
            {
                var pkgDir = string.Format("{0}.{1}", pkgId, pkg.OnlineVersion);

                // clean up removing installed version
                pkgDir = HttpContext.Current.Server.MapPath(string.Format("{0}App_Data/packages/{1}", Utils.ApplicationRelativeWebRoot, pkgDir));
                if (Directory.Exists(pkgDir))
                {
                    ForceDeleteDirectory(pkgDir);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Remove package files
        /// </summary>
        /// <param name="pkgId">Package Id</param>
        public static void UninstallPackage(string pkgId)
        {
            var installedFiles = BlogService.InstalledFromGalleryPackageFiles(pkgId);

            if (installedFiles.Count == 0)
            {
                Utils.Log(string.Format("Can not find any files installed for package: {0}", pkgId));
                throw new ApplicationException("No files to uninstall");
            }

            var repo = new BlogEngine.Core.Data.PackageRepository();
            var pkg = repo.FindById(pkgId);
            
            foreach (var file in installedFiles.OrderByDescending(f => f.FileOrder))
            {
                var fullPath = HttpContext.Current.Server.MapPath(Path.Combine(Utils.RelativeWebRoot, file.FilePath));

                if(file.IsDirectory)
                {
                    var folder = new DirectoryInfo(fullPath);
                    if (folder.Exists)
                    {
                        try
                        {
                            Directory.Delete(fullPath, true);
                        }
                        catch (Exception)
                        {
                            // this is to fix locking issue that
                            // sometimes happens in recursive deletes
                            System.Threading.Thread.Sleep(1);
                            try
                            {
                                Directory.Delete(fullPath, true);
                            }
                            catch (Exception ex)
                            {
                                Utils.Log("Error deleting directory " + fullPath + "; " + ex.Message);
                            }
                        }
                    }
                }
                else if (File.Exists(fullPath))
                {
                    File.Delete(fullPath);
                }
            }

            if (pkg != null && !string.IsNullOrWhiteSpace(pkg.OnlineVersion))
            {
                var pkgDir = string.Format("{0}.{1}", pkgId, pkg.OnlineVersion);

                // clean up removing installed version
                pkgDir = HttpContext.Current.Server.MapPath(string.Format("{0}App_Data/packages/{1}", Utils.ApplicationRelativeWebRoot, pkgDir));
                if (Directory.Exists(pkgDir))
                {
                    ForceDeleteDirectory(pkgDir);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Remove package files
        /// </summary>
        /// <param name="pkgId">Package Id</param>
        public static void UninstallPackage(string pkgId)
        {
            var installedFiles = BlogService.InstalledFromGalleryPackageFiles(pkgId);
            var repo = new BlogEngine.Core.Data.PackageRepository();
            var pkg = repo.FindById(pkgId);
            
            foreach (var file in installedFiles.OrderByDescending(f => f.FileOrder))
            {
                var fullPath = HttpContext.Current.Server.MapPath(Path.Combine(Utils.RelativeWebRoot, file.FilePath));

                if(file.IsDirectory)
                {
                    var folder = new DirectoryInfo(fullPath);
                    if (folder.Exists)
                    {
                        if(folder.GetFileSystemInfos().Length == 0)
                        {
                            ForceDeleteDirectory(fullPath);
                        }
                        else
                        {
                            Utils.Log(string.Format("Package Uninstaller: can not remove directory if it is not empty ({0})", fullPath));
                        }
                    }

                }
                else if (File.Exists(fullPath))
                {
                    File.Delete(fullPath);
                }
            }

            if (!string.IsNullOrWhiteSpace(pkg.LocalVersion))
            {
                var pkgDir = string.Format("{0}.{1}", pkgId, pkg.LocalVersion);

                // clean up removing installed version
                pkgDir = HttpContext.Current.Server.MapPath(string.Format("{0}App_Data/packages/{1}", Utils.ApplicationRelativeWebRoot, pkgDir));
                if (Directory.Exists(pkgDir))
                {
                    ForceDeleteDirectory(pkgDir);
                }
            }
        }