示例#1
0
        public OutputEntry AddOutput(CIContainer aContainer, string aFileName, TOutputStatus aStatus)
        {
            OutputEntry output = new OutputEntry(aContainer, aFileName, aStatus);

            iOutputs.Add(output);
            return(output);
        }
示例#2
0
        public static void Main()
        {
            World world = new();

            WorldSetup.Apply(world, out Entity playerEntity, out Entity startLocation);
            OutputEntry description = DescriptionUtilities.GetDescription(startLocation, playerEntity);

            Console.WriteLine(description.AsPlainText());

            while (true)
            {
                world.Run();
            }
        }
示例#3
0
        public static void AddOutput(OutputEntry output)
        {
            if (output == null)
            {
                return;
            }

            foreach (var item in _outputList)
            {
                item.ShowDetails     = false;
                item.ShowEnumeration = false;
            }

            output.ShowDetails     = true;
            output.ShowEnumeration = true;
            if (_outputList.Count >= OUTPUT_LENGHT)
            {
                _outputList.RemoveLast();
            }
            _outputList.AddFirst(output);
        }
示例#4
0
        public OutputSchema GetReduction(InputSchema requests)
        {
            var response = new OutputSchema();

            requests.SellEntries = requests.BuyEntries.OrderBy(b => b.Value).ThenByDescending(b => b.IsMarket).ToList();
            requests.BuyEntries  = requests.BuyEntries.OrderByDescending(b => b.Value).ThenBy(b => b.IsMarket).ToList();

            while (requests.SellEntries.Count() > 0 || requests.BuyEntries.Count() > 0)
            {
                var sell   = requests.SellEntries.FirstOrDefault();
                var buy    = requests.BuyEntries.FirstOrDefault();
                var output = new OutputEntry();
                output.BuyOrderId  = buy.Id;
                output.SellOrderId = sell.Id;

                if (sell.Volume > buy.Volume)
                {
                    output.Value  = buy.Value;
                    output.Volume = buy.Volume;
                    sell.Volume  -= buy.Volume;

                    response.OutputEnties.Add(output);

                    requests.BuyEntries.Remove(buy);
                }
                else
                {
                    output.Value  = buy.Value;
                    output.Volume = sell.Volume;
                    buy.Volume   -= sell.Volume;

                    response.OutputEnties.Add(output);

                    requests.SellEntries.Remove(sell);
                }
            }

            response.IsOk = true;
            return(response);
        }
示例#5
0
        // files inside archive are aligned to 0x10 boundary.
        // to convert DateTime structure into entry time:
        // entry.FileTime = file_info.CreationTimeUtc.Ticks;
        //
        // last two bytes of archive is CRC16 of the whole file
        public override void Create(Stream output, IEnumerable<Entry> list, ResourceOptions options,
                                     EntryCallback callback)
        {
            const long data_offset = 0x10;
            var encoding = Encodings.cp932.WithFatalFallback();
            int callback_count = 0;

            var output_list = new List<OutputEntry> (list.Count());
            foreach (var entry in list)
            {
                try
                {
                    string name = Path.GetFileNameWithoutExtension (entry.Name);
                    string ext  = Path.GetExtension (entry.Name);
                    byte[] name_buf = new byte[0x15];
                    byte[] ext_buf  = new byte[3];
                    encoding.GetBytes (name, 0, name.Length, name_buf, 0);
                    if (!string.IsNullOrEmpty (ext))
                    {
                        ext = ext.TrimStart ('.').ToLowerInvariant();
                        encoding.GetBytes (ext, 0, ext.Length, ext_buf, 0);
                    }
                    var out_entry = new OutputEntry
                    {
                        Name      = entry.Name,
                        IndexName = name_buf,
                        IndexExt  = ext_buf,
                    };
                    output_list.Add (out_entry);
                }
                catch (EncoderFallbackException X)
                {
                    throw new InvalidFileName (entry.Name, arcStrings.MsgIllegalCharacters, X);
                }
                catch (ArgumentException X)
                {
                    throw new InvalidFileName (entry.Name, arcStrings.MsgFileNameTooLong, X);
                }
            }

            if (null != callback)
                callback (output_list.Count+2, null, null);

            output.Position = data_offset;
            uint current_offset = 0;
            foreach (var entry in output_list)
            {
                if (null != callback)
                    callback (callback_count++, entry, arcStrings.MsgAddingFile);

                entry.FileTime = File.GetCreationTimeUtc (entry.Name).Ticks;
                entry.Offset = current_offset;
                entry.CompressionType = 0;
                using (var input = File.OpenRead (entry.Name))
                {
                    var size = input.Length;
                    if (size > uint.MaxValue || current_offset + size + 0x0f > uint.MaxValue)
                        throw new FileSizeException();
                    entry.Size = (uint)size;
                    entry.UnpackedSize = entry.Size;
                    using (var checked_stream = new CheckedStream (output, new Crc16()))
                    {
                        input.CopyTo (checked_stream);
                        entry.HasCheckSum = true;
                        entry.CheckSum = (ushort)checked_stream.CheckSumValue;
                    }
                    current_offset += (uint)size + 0x0f;
                    current_offset &= ~0x0fu;
                    output.Position = data_offset + current_offset;
                }
            }

            if (null != callback)
                callback (callback_count++, null, arcStrings.MsgUpdatingIndex);

            // at last, go back to directory and write offset/sizes
            uint index_offset = current_offset;
            using (var index = new BinaryWriter (output, encoding, true))
            {
                foreach (var entry in output_list)
                {
                    index.Write (entry.IndexName);
                    index.Write (entry.IndexExt);
                    index.Write ((uint)entry.Offset);
                    index.Write (entry.UnpackedSize);
                    index.Write (entry.Size);
                    index.Write (entry.CompressionType);
                    index.Write (entry.HasCheckSum);
                    index.Write (entry.CheckSum);
                    index.Write (entry.FileTime);
                }
                index.BaseStream.Position = 0;
                index.Write (Signature);
                index.Write (0x03006b63);
                index.Write (index_offset);
                index.Write (output_list.Count);

                if (null != callback)
                    callback (callback_count++, null, arcStrings.MsgCalculatingChecksum);

                output.Position = 0;
                using (var checked_stream = new CheckedStream (output, new Crc16()))
                {
                    checked_stream.CopyTo (Stream.Null);
                    index.Write ((ushort)checked_stream.CheckSumValue);
                }
            }
        }
        public static string ToConsole(OutputEntry entry, bool verbose)
        {
            var result = new StringBuilder();

            result.AppendPrefix(entry)
                .Append(ToConsole(entry.Messsage));

            if (!verbose)
            {
                entry.ProcessedFields.Where(f => f.Matched)
                    .Where(f => !f.Field.EndsWith("Library Name"))
                    .OrderBy(f => GetProcessedFieldSortPrefix(f) + f.Field)
                    .ForEach(f =>
                    {
                        result.AppendLine()
                            .AppendPrefix(entry)
                            .Append("   ")
                            .Append(f.Field)
                            .Append(": ")
                            .Append(f.Value);
                    });
            }
            else
            {
                if (entry is RuleOutputEntry)
                {
                    result.AppendLine()
                        .AppendPrefix(entry)
                        .Append("   ")
                        .Append(Simplify(((RuleOutputEntry) entry).Rule.Location.LineText));
                }

                entry.ProcessedFields.Where(f => f.Matched)
                    .OrderBy(f => GetProcessedFieldSortPrefix(f) + f.Field)
                    .ForEach(f =>
                    {
                        result.AppendLine()
                            .AppendPrefix(entry)
                            .Append("   ")
                            .Append(f.Field)
                            .Append(": ")
                            .Append(f.Value);
                    });

                if (entry.Projects.Any())
                {
                    result.AppendLine()
                        .AppendPrefix(entry)
                        .Append("   Projects affected:");
                    entry.Projects.ForEach(p => result.AppendLine()
                        .AppendPrefix(entry)
                        .Append("      - ")
                        .Append(ToConsole(p, OutputMessage.ProjInfo.NameAndPath)));
                }

                if (entry.Dependencies.Any())
                {
                    result.AppendLine()
                        .AppendPrefix(entry)
                        .Append("   Dependencies affected:");
                    entry.Dependencies.ForEach(d => result.AppendLine()
                        .AppendPrefix(entry)
                        .Append("      - ")
                        .Append(ToConsole(d, OutputMessage.DepInfo.FullDescription)));
                }
            }

            return result.ToString();
        }
        public static StringBuilder AppendPrefix(this StringBuilder result, OutputEntry entry)
        {
            result.Append("[");
            if (entry is DependencyRuleMatch && ((DependencyRuleMatch) entry).Allowed)
                result.Append("ALLOWED");
            else
                result.Append(entry.Severity.ToString()
                    .ToUpper());
            result.Append("] ");

            return result;
        }
示例#8
0
 public static void RemoveOutput(OutputEntry deleted)
 {
     _outputList.Remove(deleted);
 }
示例#9
0
        // files inside archive are aligned to 0x10 boundary.
        // to convert DateTime structure into entry time:
        // entry.FileTime = file_info.CreationTimeUtc.Ticks;
        //
        // last two bytes of archive is CRC16 of the whole file

        public override void Create(Stream output, IEnumerable <Entry> list, ResourceOptions options,
                                    EntryCallback callback)
        {
            const long data_offset    = 0x10;
            var        encoding       = Encodings.cp932.WithFatalFallback();
            int        callback_count = 0;

            var output_list = new List <OutputEntry> (list.Count());

            foreach (var entry in list)
            {
                try
                {
                    string name     = Path.GetFileNameWithoutExtension(entry.Name);
                    string ext      = Path.GetExtension(entry.Name);
                    byte[] name_buf = new byte[0x15];
                    byte[] ext_buf  = new byte[3];
                    encoding.GetBytes(name, 0, name.Length, name_buf, 0);
                    if (!string.IsNullOrEmpty(ext))
                    {
                        ext = ext.TrimStart('.').ToLowerInvariant();
                        encoding.GetBytes(ext, 0, ext.Length, ext_buf, 0);
                    }
                    var out_entry = new OutputEntry
                    {
                        Name      = entry.Name,
                        IndexName = name_buf,
                        IndexExt  = ext_buf,
                    };
                    output_list.Add(out_entry);
                }
                catch (EncoderFallbackException X)
                {
                    throw new InvalidFileName(entry.Name, arcStrings.MsgIllegalCharacters, X);
                }
                catch (ArgumentException X)
                {
                    throw new InvalidFileName(entry.Name, arcStrings.MsgFileNameTooLong, X);
                }
            }

            if (null != callback)
            {
                callback(output_list.Count + 2, null, null);
            }

            output.Position = data_offset;
            uint current_offset = 0;

            foreach (var entry in output_list)
            {
                if (null != callback)
                {
                    callback(callback_count++, entry, arcStrings.MsgAddingFile);
                }

                entry.FileTime        = File.GetCreationTimeUtc(entry.Name).Ticks;
                entry.Offset          = current_offset;
                entry.CompressionType = 0;
                using (var input = File.OpenRead(entry.Name))
                {
                    var size = input.Length;
                    if (size > uint.MaxValue || current_offset + size + 0x0f > uint.MaxValue)
                    {
                        throw new FileSizeException();
                    }
                    entry.Size         = (uint)size;
                    entry.UnpackedSize = entry.Size;
                    using (var checked_stream = new CheckedStream(output, new Crc16()))
                    {
                        input.CopyTo(checked_stream);
                        entry.HasCheckSum = true;
                        entry.CheckSum    = (ushort)checked_stream.CheckSumValue;
                    }
                    current_offset += (uint)size + 0x0f;
                    current_offset &= ~0x0fu;
                    output.Position = data_offset + current_offset;
                }
            }

            if (null != callback)
            {
                callback(callback_count++, null, arcStrings.MsgUpdatingIndex);
            }

            // at last, go back to directory and write offset/sizes
            uint index_offset = current_offset;

            using (var index = new BinaryWriter(output, encoding, true))
            {
                foreach (var entry in output_list)
                {
                    index.Write(entry.IndexName);
                    index.Write(entry.IndexExt);
                    index.Write((uint)entry.Offset);
                    index.Write(entry.UnpackedSize);
                    index.Write(entry.Size);
                    index.Write(entry.CompressionType);
                    index.Write(entry.HasCheckSum);
                    index.Write(entry.CheckSum);
                    index.Write(entry.FileTime);
                }
                index.BaseStream.Position = 0;
                index.Write(Signature);
                index.Write(0x03006b63);
                index.Write(index_offset);
                index.Write(output_list.Count);

                if (null != callback)
                {
                    callback(callback_count++, null, arcStrings.MsgCalculatingChecksum);
                }

                output.Position = 0;
                using (var checked_stream = new CheckedStream(output, new Crc16()))
                {
                    checked_stream.CopyTo(Stream.Null);
                    index.Write((ushort)checked_stream.CheckSumValue);
                }
            }
        }
示例#10
0
 public void AddLine(OutputEntry output)
 {
     Content.AddRange(output.Content);
     Add("\n");
 }