Exemplo n.º 1
0
        private static void ExtractFiles(FileList fileList, IFileWriter writer)
        {
            Console.WriteLine($"Extracting {fileList.Name}");

            writer.CreateDirectory(fileList.Name);

            foreach (FileData file in fileList.GetFiles())
            {
                if (file.Compressed)
                {
                    using (var compressed = new MemoryStream(file.Contents))
                    {
                        using (var decompressed = new MemoryStream())
                        {
                            LZSS.Decompress(compressed, decompressed);
                            file.Contents = decompressed.ToArray();
                        }
                    }
                }

                if (file.IsArchive())
                {
                    ExtractFiles(new ArchiveFileList(Path.Combine(fileList.Name, file.Name), file.Contents), writer);
                }
                else
                {
                    writer.Write(Path.Combine(fileList.Name, $"{file.Name}.{file.GetExtension()}"), file.Contents);
                }
            }
        }
Exemplo n.º 2
0
        private void InitializeFile()
        {
            var formattedDate = _dateTimeProvider.FormatDateFull(_creationDateTime);
            var nameLine      = $"# {_logName}  ";
            var dateLine      = $"#### Initialized On {formattedDate}  ";
            var initialLines  = new [] { nameLine, dateLine, "---", "---", "" };

            _wrappedFileWriter.CreateDirectory(_dirPath);
            _wrappedFileWriter.WriteAllLines(_filePath, initialLines);
        }
Exemplo n.º 3
0
        public async Task <Directory> CreateDirectory(string name, string directoryPath, bool isPrivate = false, string parentDirectoryId = null)
        {
            string fullPath = $"{directoryPath}{name}";

            if (!fileWriter.CreateDirectory(fullPath))
            {
                ErrorWriter.Append("Directory name already exists");
                return(null);
            }

            var directory = new DirectoryBuilder()
                            .SetName(name)
                            .SetPath(fullPath)
                            .AssignedTo(!isPrivate ? null : currentUserId)
                            .WithParentDirectory(parentDirectoryId)
                            .Build();

            database.DirectoryRepository.Add(directory);

            return(await database.Complete() ? directory : null);
        }