Example #1
0
        public static void PhoneSaveItems(QcdmManager manager, Dictionary <string, object> items, Logger logger)
        {
            var efs = manager.Efs;

            foreach (var item in items)
            {
                var type          = item.Value.GetType();
                var fileAttribute = EfsFileAttributeUtils.Get(type);
                if (fileAttribute == null)
                {
                    var nvItemIdAttribute = NvItemIdAttributeUtils.Get(type);
                    if (nvItemIdAttribute != null && nvItemIdAttribute.Id <= UInt16.MaxValue)
                    {
                        using (var stream = NvOpenWrite(manager, (ushort)nvItemIdAttribute.Id))
                        {
                            ItemsBinarySerializer.Serialize(item.Value, stream);
                            stream.Flush();
                            stream.Close();
                        }
                    }
                }
                else
                {
                    var path             = fileAttribute.Path;
                    var subscriptionPath = PathUtils.GetSubscriptionPath(path, 1);
                    if (efs.FileExists(subscriptionPath))
                    {
                        efs.DeleteFile(subscriptionPath);
                    }
                    else
                    {
                        subscriptionPath = string.Empty;
                    }
                    using (var stream = fileAttribute.IsItemFile
                        ? FileUtils.PhoneItemCreateWrite(manager, path, fileAttribute.Permissions, logger)
                        : FileUtils.PhoneCreateWrite(manager, path, fileAttribute.Permissions, logger))
                    {
                        ItemsBinarySerializer.Serialize(item.Value, stream);
                        stream.Flush();
                        stream.Close();
                    }

                    if (!string.IsNullOrEmpty(subscriptionPath))
                    {
                        using (var stream = fileAttribute.IsItemFile
                            ? FileUtils.PhoneItemCreateWrite(manager, subscriptionPath, fileAttribute.Permissions,
                                                             logger)
                            : FileUtils.PhoneCreateWrite(manager, subscriptionPath, fileAttribute.Permissions, logger))
                        {
                            ItemsBinarySerializer.Serialize(item.Value, stream);
                            stream.Flush();
                            stream.Close();
                        }
                    }
                }
            }
        }
Example #2
0
        public static void LocalSaveItems(string directoryPath, Dictionary <string, object> items, Logger logger)
        {
            foreach (var item in items)
            {
                var type          = item.Value.GetType();
                var fileAttribute = EfsFileAttributeUtils.Get(type);
                if (fileAttribute == null)
                {
                    var nvItemIdAttribute = NvItemIdAttributeUtils.Get(type);
                    if (nvItemIdAttribute != null && nvItemIdAttribute.Id <= UInt16.MaxValue)
                    {
                        var nvItemFileName = PathUtils.GetNvItemFileName((ushort)nvItemIdAttribute.Id);
                        var path           = Path.Combine(directoryPath, nvItemFileName);
                        using (var stream = FileUtils.LocalCreateWrite(path))
                        {
                            ItemsBinarySerializer.Serialize(item.Value, stream);
                            stream.Flush();
                            stream.Close();
                        }
                    }
                }
                else
                {
                    var filePath         = fileAttribute.Path;
                    var subscriptionPath = PathUtils.GetSubscriptionPath(filePath, 1);
                    subscriptionPath = Path.Combine(directoryPath, subscriptionPath);
                    if (File.Exists(subscriptionPath))
                    {
                        File.Delete(subscriptionPath);
                    }
                    else
                    {
                        subscriptionPath = null;
                    }
                    var entryType = fileAttribute.IsItemFile ? DirectoryEntryType.ItemFile : DirectoryEntryType.File;
                    var path      = PathUtils.BuildPath(directoryPath, filePath, fileAttribute.Permissions, entryType,
                                                        false);
                    using (var stream = FileUtils.LocalCreateWrite(path))
                    {
                        ItemsBinarySerializer.Serialize(item.Value, stream);
                        stream.Flush();
                        stream.Close();
                    }

                    if (!string.IsNullOrEmpty(subscriptionPath))
                    {
                        using (var stream = FileUtils.LocalCreateWrite(subscriptionPath))
                        {
                            ItemsBinarySerializer.Serialize(item.Value, stream);
                            stream.Flush();
                            stream.Close();
                        }
                    }
                }
            }
        }
Example #3
0
        public static Dictionary <string, object> LocalLoadItems(string directoryPath, HashSet <string> configItems)
        {
            var items = new Dictionary <string, object>();

            foreach (var fileUnixPath in ItemsFactory.SupportedEfsFilePaths)
            {
                var item     = ItemsFactory.CreateEfsFile(fileUnixPath);
                var itemType = item.GetType();
                if (configItems == null || configItems.Contains(itemType.Name))
                {
                    var filePath      = fileUnixPath.Replace('/', '\\');
                    var fileAttribute = EfsFileAttributeUtils.Get(itemType);
                    var path          = fileAttribute == null
                        ? $"{directoryPath}{filePath}"
                        : PathUtils.BuildPath(directoryPath, filePath, fileAttribute.Permissions,
                                              fileAttribute.IsItemFile ? DirectoryEntryType.ItemFile : DirectoryEntryType.File, false);
                    if (!File.Exists(path))
                    {
                        path = $"{directoryPath}{filePath}";
                    }
                    if (File.Exists(path))
                    {
                        using (var stream = FileUtils.LocalOpenRead(path))
                        {
                            ItemsBinarySerializer.Deserialize(item, stream);
                            stream.Close();
                        }
                    }

                    items.Add(itemType.Name, item);
                }
            }

            foreach (var nvItemId in ItemsFactory.SupportedNvItemIds)
            {
                var item     = ItemsFactory.CreateNvItem(nvItemId);
                var itemType = item.GetType();
                if (configItems == null || configItems.Contains(itemType.Name))
                {
                    var nvItemFileName = PathUtils.GetNvItemFileName((ushort)nvItemId);
                    var path           = Path.Combine(directoryPath, nvItemFileName);
                    if (File.Exists(path))
                    {
                        using (var stream = FileUtils.LocalOpenRead(path))
                        {
                            ItemsBinarySerializer.Deserialize(item, stream);
                            stream.Close();
                        }
                    }

                    items.Add(itemType.Name, item);
                }
            }

            return(items);
        }
Example #4
0
        public static void LocalSaveItem(string directoryPath, int subscription, object item,
                                         Logger logger, bool verbose)
        {
            var type          = item.GetType();
            var fileAttribute = EfsFileAttributeUtils.Get(type);

            if (fileAttribute == null)
            {
                var nvItemIdAttribute = NvItemIdAttributeUtils.Get(type);
                if (nvItemIdAttribute != null && nvItemIdAttribute.Id <= ushort.MaxValue)
                {
                    if (verbose)
                    {
                        logger.LogInfo(string.Format(Strings.QcdmProcessingFormat, type.Name));
                    }
                    var nvItemFileName = PathUtils.GetNvItemFileName((ushort)nvItemIdAttribute.Id);
                    var path           = Path.Combine(directoryPath, nvItemFileName);
                    using (var stream = FileUtils.LocalCreateWrite(path))
                    {
                        ItemsBinarySerializer.Serialize(item, stream);
                        stream.Flush();
                        stream.Close();
                    }
                }
            }
            else
            {
                if (verbose)
                {
                    logger.LogInfo(string.Format(Strings.QcdmProcessingFormat, fileAttribute.Path));
                }
                var filePath  = PathUtils.GetEfsFilePath(fileAttribute.Path, subscription);
                var entryType = fileAttribute.IsItemFile ? DirectoryEntryType.ItemFile : DirectoryEntryType.File;
                var path      = PathUtils.BuildPath(directoryPath, filePath, fileAttribute.Permissions, entryType,
                                                    false);

                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                using (var stream = FileUtils.LocalCreateWrite(path))
                {
                    ItemsBinarySerializer.Serialize(item, stream);
                    stream.Flush();
                    stream.Close();
                }
            }
        }
Example #5
0
        public static Dictionary <string, object> LocalLoadItems(string directoryPath, int subscription, Logger logger, bool verbose)
        {
            var items = new Dictionary <string, object>();

            foreach (var fileUnixPath in ItemsFactory.SupportedEfsFilePaths)
            {
                var itemType      = ItemsFactory.GetEfsFileType(fileUnixPath);
                var fileAttribute = EfsFileAttributeUtils.Get(itemType);
                var filePath      = PathUtils.GetEfsFilePath(fileUnixPath, subscription);
                filePath = filePath.Replace('/', '\\');
                var path = fileAttribute == null
                    ? $"{directoryPath}{filePath}"
                    : PathUtils.BuildPath(directoryPath, filePath, fileAttribute.Permissions,
                                          fileAttribute.IsItemFile ? DirectoryEntryType.ItemFile : DirectoryEntryType.File, false);
                if (!File.Exists(path))
                {
                    path = $"{directoryPath}{filePath}";
                    path = PathUtils.FindFile($"{path}__");
                }
                if (!File.Exists(path))
                {
                    path = $"{directoryPath}{filePath}";
                }

                if (File.Exists(path))
                {
                    using (var stream = FileUtils.LocalOpenRead(path))
                    {
                        if (verbose)
                        {
                            logger.LogInfo(string.Format(Strings.QcdmProcessingFormat, path));
                        }
                        var item = ItemsBinarySerializer.Deserialize(stream, itemType);
                        items.Add(itemType.Name, item);
                        stream.Close();
                    }
                }
            }

            foreach (var nvItemId in ItemsFactory.SupportedNvItemIds)
            {
                var itemType       = ItemsFactory.GetNvItemType(nvItemId);
                var nvItemFileName = PathUtils.GetNvItemFileName((ushort)nvItemId);
                var path           = Path.Combine(directoryPath, nvItemFileName);
                if (File.Exists(path))
                {
                    using (var stream = FileUtils.LocalOpenRead(path))
                    {
                        if (verbose)
                        {
                            logger.LogInfo(string.Format(Strings.QcdmProcessingFormat, itemType));
                        }
                        var item = ItemsBinarySerializer.Deserialize(stream, itemType);
                        items.Add(itemType.Name, item);
                        stream.Close();
                    }
                }
            }

            return(items);
        }
Example #6
0
        public static void PhoneSaveItems(QcdmManager manager, int subscription, Dictionary <string, object> items,
                                          Logger logger, bool verbose)
        {
            var efs = manager.Efs;

            foreach (var item in items)
            {
                var type          = item.Value.GetType();
                var fileAttribute = EfsFileAttributeUtils.Get(type);
                if (fileAttribute == null)
                {
                    var nvItemIdAttribute = NvItemIdAttributeUtils.Get(type);
                    if (nvItemIdAttribute != null && nvItemIdAttribute.Id <= ushort.MaxValue)
                    {
                        if (verbose)
                        {
                            logger.LogInfo(string.Format(Strings.QcdmProcessingFormat, type.Name));
                        }
                        using (var memoryStream = new MemoryStream())
                        {
                            ItemsBinarySerializer.Serialize(item.Value, memoryStream);
                            memoryStream.Flush();
                            memoryStream.Position = 0;
                            using (var stream = NvOpenWrite(manager, (ushort)nvItemIdAttribute.Id))
                            {
                                StreamUtils.Copy(memoryStream, stream);
                                stream.Flush();
                                stream.Close();
                            }
                            memoryStream.Close();
                        }
                    }
                }
                else
                {
                    var path = PathUtils.GetEfsFilePath(fileAttribute.Path, subscription);
                    if (verbose)
                    {
                        logger.LogInfo(string.Format(Strings.QcdmProcessingFormat, fileAttribute.Path));
                    }

                    if (efs.FileExists(path))
                    {
                        efs.DeleteFile(path);
                    }

                    using (var memoryStream = new MemoryStream())
                    {
                        ItemsBinarySerializer.Serialize(item.Value, memoryStream);
                        memoryStream.Flush();
                        memoryStream.Position = 0;
                        using (var stream = fileAttribute.IsItemFile
                        ? FileUtils.PhoneItemCreateWrite(manager, path, fileAttribute.Permissions, logger)
                        : FileUtils.PhoneCreateWrite(manager, path, fileAttribute.Permissions, logger))
                        {
                            StreamUtils.Copy(memoryStream, stream);
                            stream.Flush();
                            stream.Close();
                        }
                        memoryStream.Close();
                    }
                }
            }
        }