예제 #1
0
        //public void WriteSizedBytes(byte[] data)
        //{
        //    Write((uint)data.Length);
        //    base.Write(data);
        //}

        public override void Close()
        {
            base.Close();
            OutStream.Close();
            Dispose(true);
            OutStream.Dispose();
        }
예제 #2
0
파일: Frame.cs 프로젝트: elliottmatt/frame
        public int Run()
        {
            if (!DynamicFields)
            {
                // read through and get the stats
                int n = GetFileStats();
                if (n > 0)
                {
                    return(n);
                }
            }

            try
            {
                OutStream = (WriteStdout ? Console.Out : new StreamWriter(FilenameOut));

                if (UseTwoPassMethod || DynamicFields)
                {
                    throw new Exception("TODO 2 pass");
                }
                else
                {
                    return(PrintOutFrame());
                }
            }
            finally
            {
                if (OutStream != null && OutStream != Console.Out)
                {
                    try { OutStream.Close(); } catch { }
                    try { OutStream.Dispose(); } catch { }
                }
            }
        }
예제 #3
0
 private void CloseOutput()
 {
     if (string.IsNullOrEmpty(OutputFile))
     {
         return;
     }
     Console.WriteLine("</pre>");
     Writer.Close();
     OutStream.Close();
 }
예제 #4
0
        public override string ToString()
        {
            OutStream.Close();

            // Add a blank space after all forward-slashes to work around a bug where
            // forward-slashes are unescaped when written to the save file and and
            // consectuive forward slashes end up being treated as the start of a line
            // comment and the saved file is truncated when read.
            // See: http://bugs.kerbalspaceprogram.com/issues/821
            return(Convert.ToBase64String(_memoryStream.ToArray()).Replace("/", "/ "));
        }
예제 #5
0
        /// <summary>
        /// Leave from a specified channel.
        /// </summary>
        /// <param name="channelId">Channel id.</param>
        public async Task LeaveVoice()
        {
            if (ChannelConnection != null)
            {
                await ChannelConnection(this, new ChannelEventArgs(CurrentChannel, false));
            }

            CurrentChannel = null;

            // Disconnect audio streams
            if (OutStream != null)
            {
                OutStream.Close();
            }

            // leave voice chat
            await Client.StopAsync();

            Client    = null;
            OutStream = null;
        }
예제 #6
0
        private void WritePartition(string Name, string FilePath, Action <int, TimeSpan?> ProgressUpdateCallback, ProgressUpdater UpdaterPerSector, bool Compress = false)
        {
            Partition Target = GPT.Partitions.Find(p => string.Equals(p.Name, Name, StringComparison.CurrentCultureIgnoreCase));

            if (Target == null)
            {
                throw new ArgumentOutOfRangeException();
            }

            int FirstChunk = GetChunkIndexFromSectorIndex((int)Target.FirstSector);
            int LastChunk  = GetChunkIndexFromSectorIndex((int)Target.LastSector);

            ProgressUpdater Updater = UpdaterPerSector;

            if ((Updater == null) && (ProgressUpdateCallback != null))
            {
                Updater = new ProgressUpdater(Target.LastSector - Target.FirstSector + 1, ProgressUpdateCallback);
            }

            byte[] Buffer = new byte[ChunkSize];

            OpenFile();

            FileStream OutputFile = new(FilePath, FileMode.Create, FileAccess.Write);
            Stream     OutStream  = OutputFile;

            // We use gzip compression
            //
            // LZMA is about 60 times slower (compression is twice as good, but compressed size is already really small, so it doesnt matter much)
            // OutStream = new LZMACompressionStream(OutputFile, System.IO.Compression.CompressionMode.Compress, false);
            //
            // DeflateStream is a raw compression stream without recognizable header
            // Deflate has almost no performance penalty
            // OutStream = new DeflateStream(OutputFile, CompressionLevel.Optimal, false);
            //
            // GZip can be recognized. It always starts with 1F 8B 08 (1F 8B is the magic value, 08 is the Deflate compression method)
            // With GZip compression, dump time goes from 1m to 1m37s. So that doesnt matter much.
            if (Compress)
            {
                OutStream = new CompressedStream(OutputFile, (Target.LastSector - Target.FirstSector + 1) * 0x200);
            }

            for (int j = FirstChunk; j <= LastChunk; j++)
            {
                GetChunk(Buffer, j);

                int FirstSector = 0;
                int LastSector  = (ChunkSize / 0x200) - 1;

                if (j == FirstChunk)
                {
                    FirstSector = GetSectorNumberInChunkFromSectorIndex((int)Target.FirstSector);
                }

                if (j == LastChunk)
                {
                    LastSector = GetSectorNumberInChunkFromSectorIndex((int)Target.LastSector);
                }

                int Offset = FirstSector * 0x200;
                int Size   = (LastSector - FirstSector + 1) * 0x200;

                OutStream.Write(Buffer, Offset, Size);

                Updater?.IncreaseProgress((UInt64)(ChunkSize / 0x200));
            }

            OutStream.Close();

            CloseFile();
        }
예제 #7
0
        public int Run()
        {
            TextReader instream = null;

            try
            {
                OutStream = (WriteStdout ? Console.Out : new StreamWriter(FilenameOut));
                instream  = (ReadStdin ? Console.In : new StreamReader(FilenameIn));

                if (Verbose)
                {
                    for (int i = 0; i < Fields.Count; ++i)
                    {
                        Field f = Fields[i];
                        OutStream.WriteLine(String.Format("Field{0}|{1}|{2}|",
                                                          i,
                                                          f.VerboseType,
                                                          f.VerboseDefinition
                                                          )
                                            );
                    }
                }

                for (int row = 0; ; row++)
                {
                    string line = instream.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    string[] arr = ParseClass.ParseLine(line, TrimFields, Delimiter, PreserveQuotes, QuoteChar);
                    PrintFields(arr);
                    if (PrintTrailingDelim)
                    {
                        OutStream.Write(OutDelimiter);
                    }
                    OutStream.WriteLine();
                }

                return(0);
            }
            finally
            {
                if (instream != null && instream != Console.In)
                {
                    try { instream.Close(); }
                    catch { }
                    try { instream.Dispose(); }
                    catch { }
                }

                if (OutStream != null && OutStream != Console.Out)
                {
                    try { OutStream.Close(); }
                    catch { }
                    try { OutStream.Dispose(); }
                    catch { }
                }
            }
        }