// Writes Chunk c's state metadata into given buffer
    // and returns the amount of bytes written
    public static int CompressMetadataState(Chunk c, byte[] buffer)
    {
        List <ushort> palleteList = Compression.GetPallete(Pallete.METADATA);
        int           bytes;

        NativeArray <int> writtenBytes = new NativeArray <int>(new int[1] {
            0
        }, Allocator.TempJob);
        NativeArray <ushort> chunkData    = new NativeArray <ushort>(c.metadata.GetStateData(), Allocator.TempJob);
        NativeArray <byte>   buff         = new NativeArray <byte>(buffer, Allocator.TempJob);
        NativeArray <ushort> palleteArray = new NativeArray <ushort>(palleteList.ToArray(), Allocator.TempJob);

        CompressionJob cmdJob = new CompressionJob {
            chunkData    = chunkData,
            buffer       = buff,
            palleteArray = palleteArray,
            writtenBytes = writtenBytes
        };

        JobHandle handle = cmdJob.Schedule();

        handle.Complete();

        // NativeArray to Array convertion
        buff.CopyTo(buffer);

        bytes = writtenBytes[0];

        chunkData.Dispose();
        palleteArray.Dispose();
        buff.Dispose();
        writtenBytes.Dispose();

        return(bytes);
    }
Beispiel #2
0
    // Writes Chunk c's HP metadata into given buffer
    // and returns the amount of bytes written
    public static int CompressMetadataHP(Chunk c, byte[] buffer, int targetPos = 0)
    {
        List <ushort> palleteList = Compression.GetPallete(Pallete.METADATA);
        int           bytes;

        NativeArray <int> writtenBytes = new NativeArray <int>(new int[1] {
            0
        }, Allocator.TempJob);
        NativeArray <ushort> chunkData    = NativeTools.CopyToNative(c.metadata.GetHPData());
        NativeArray <byte>   buff         = NativeTools.CopyToNative(buffer);
        NativeArray <ushort> palleteArray = NativeTools.CopyToNative(palleteList.ToArray());

        CompressionJob cmdJob = new CompressionJob {
            chunkData    = chunkData,
            buffer       = buff,
            palleteArray = palleteArray,
            writtenBytes = writtenBytes
        };

        JobHandle handle = cmdJob.Schedule();

        handle.Complete();

        NativeArray <byte> .Copy(buff, 0, buffer, targetPos, writtenBytes[0]);

        bytes = writtenBytes[0];

        chunkData.Dispose();
        palleteArray.Dispose();
        buff.Dispose();
        writtenBytes.Dispose();

        return(bytes);
    }
    // Writes Chunk c's data using a Pallete's compression into given buffer
    // and returns the amount of bytes written
    public static int CompressBlocks(Chunk c, byte[] buffer)
    {
        int           bytes;
        Pallete       p           = Compression.BiomeToPallete(c.biomeName);
        List <ushort> palleteList = Compression.GetPallete(p);


        NativeArray <int> writtenBytes = new NativeArray <int>(new int[1] {
            0
        }, Allocator.TempJob);
        NativeArray <ushort> chunkData    = new NativeArray <ushort>(c.data.GetData(), Allocator.TempJob);
        NativeArray <byte>   buff         = new NativeArray <byte>(buffer, Allocator.TempJob);
        NativeArray <ushort> palleteArray = new NativeArray <ushort>(palleteList.ToArray(), Allocator.TempJob);

        CompressionJob cbJob = new CompressionJob {
            chunkData    = chunkData,
            buffer       = buff,
            palleteArray = palleteArray,
            writtenBytes = writtenBytes
        };

        JobHandle handle = cbJob.Schedule();

        handle.Complete();

        // NativeArray to Array convertion
        buff.CopyTo(buffer);

        bytes = writtenBytes[0];

        chunkData.Dispose();
        palleteArray.Dispose();
        buff.Dispose();
        writtenBytes.Dispose();

        return(bytes);
    }
        void Start(Collection <MetaRecord> metarecords, IEnumerable <ArchiveTask> archiveParameters)
        {
            _log.ProcedureCall("Start");

            foreach (ArchiveTask archiveParameter in archiveParameters)
            {
                var job = new CompressionJob(archiveParameter, _task.EnableEncryption, _log);

                if (NotificationEventHandler != null)
                {
                    job.NotificationEventHandler += NotificationEventHandler;
                }
                _compressionManager.AddJob(job);
            }
            _compressionManager.WaitUntilAllJobsAreDone();

            if (_aborting)
            {
                _log.ProcedureCall("Start::archiving aborted");
                return;
            }

            var imageCreationJob = new ImageCreationJob(_log, _imageFile, metarecords);

            if (NotificationEventHandler != null)
            {
                imageCreationJob.NotificationEventHandler += NotificationEventHandler;
            }
            _imageCreationManager.AddJob(imageCreationJob);
            _imageCreationManager.WaitUntilAllJobsAreDone();

            if (_aborting)
            {
                _log.ProcedureCall("Start::Image creation aborted");
                return;
            }

            foreach (StorageBase storage in _task.Storages)
            {
                var job = new CopyJob(storage, _imageFile.FileName, _task.EnableEncryption, _log);
                if (NotificationEventHandler != null)
                {
                    job.NotificationEventHandler += NotificationEventHandler;
                }
                _copyManager.AddJob(job);
            }
            _copyManager.WaitUntilAllJobsAreDone();

            if (_aborting)
            {
                _log.ProcedureCall("Start::copying storage aborted");
                return;
            }

            RunProgramsChainAfterBackup();

            if (_aborting)
            {
                _log.ProcedureCall("Start::run programs chain after backup aborted");
                return;
            }

            // removing
            if (_task.SecureDeletingOfFiles)
            {
                OverWriteFileWithZeros(_imageFile.FileName);
            }
            else
            {
                File.Delete(_imageFile.FileName);
            }
        }