Esempio n. 1
0
        internal static byte[] ReadImage(string imageName, int imageWidth)
        {
            string fullIconPath = AppItem.GetFullImagePath(imageName, imageWidth);

            byte[] result = { };
            if (File.Exists(fullIconPath))
            {
                FileInfo imageFile = new FileInfo(fullIconPath);
                if (imageFile.Length > Config.MaxViewableFileSize)
                {
                    fullIconPath = AppItem.GetFullImagePath("A", imageWidth);
                    imageFile    = new FileInfo(fullIconPath);
                }
                using (BinaryReader stream = new BinaryReader(imageFile.OpenRead()))
                {
                    result = stream.ReadBytes((int)imageFile.Length);
                }
            }
            return(result);
        }
Esempio n. 2
0
        internal static (string filePath, string directoryName) GetDirctoryPath(string DirectoryId)
        {
            AppItem item          = GetApp(DirectoryId);
            string  directoryPath = item?.GetFullPath();
            string  directoryName = item?.Name;

            if (!string.IsNullOrEmpty(directoryPath) && File.Exists(Path.Combine(directoryPath, Config.Default_DownloadableContentTag)))
            {
                long   DirectorySize    = item.GetSize();
                string zipFileName      = Shared.HashText($"{item.GetFullPath().Replace(Config.AppDirectory, "")}/{item.ChildernCount}");
                string zipFileDirectory = Path.Combine(Config.AppDirectory, Config.TempDirectoryName);
                string zipFileFullName  = Path.Combine(zipFileDirectory, $"{zipFileName}.zip");
                if (!File.Exists(zipFileFullName))
                {
                    long currentDriveFreeSpace = Shared.GetDriveFreeSize(zipFileDirectory);
                    if (DirectorySize < currentDriveFreeSpace && DirectorySize < Config.MaxDownloadableDirectorySize)
                    {
                        try
                        {
                            if (!Directory.Exists(zipFileDirectory))
                            {
                                Directory.CreateDirectory(zipFileDirectory);
                            }
                            ZipFile.CreateFromDirectory(directoryPath, zipFileFullName, CompressionLevel.Fastest, false);
                        }
                        catch (Exception) { }
                        return(zipFileFullName, directoryName);
                    }
                }
                else
                {
                    return(zipFileFullName, directoryName);
                }
            }
            return(null, null);
        }