<commit_before>﻿// Copyright (C) 2007 <NAME>
// 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

using System;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using ICSharpCode.SharpZipLib.Zip;

namespace Core.GameObjects {
    /// <summary>
    /// Betöltő, amely merevlemezről tölti be a szükséges adatokat
    /// </summary>
    class ObjectLoader_File: ObjectLoader {
        class Data {
            internal Dictionary<string,string> attributes = new Dictionary<string,string>();
            internal Dictionary<string,MemoryStream> files = new Dictionary<string,MemoryStream>();
        }

        void LoadFromFile(string id) {
            string fileName = id.Replace('.', Path.DirectorySeparatorChar)+".kfiobject";
            Data data = new Data();
            using (ZipInputStream zs = new ZipInputStream(File.OpenRead(fileName))) {
                ZipEntry entry;
                while ((entry = zs.GetNextEntry()) != null) {
                    MemoryStream m = new MemoryStream();
                    int size = 2048;
                    byte[] buffer = new byte[size];
                    while ((size = zs.Read(buffer, 0, size)) > 0) {
                        m.Write(buffer, 0, size);
                    }
                    m.Position = 0;
                    data.files.Add(entry.Name, m);
                }
            }
            if (data.files.ContainsKey("attributes.xml")) {
                XmlDocument doc = new XmlDocument();
                doc.Load(data.files["attributes.xml"]);
                XmlElement root = doc.DocumentElement;
                foreach(XmlNode element in root.ChildNodes) {
                    data.attributes.Add(element.Name, element.InnerText);
                }
            }
            /*foreach (KeyValuePair<string, MemoryStream> streams in data.files) {
                if (streams.Key == "attributes.xml") {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(streams.Value);
                    XmlElement root = doc.DocumentElement;
                    foreach(XmlNode element in root.ChildNodes) {
                        data.attributes.Add(element.Name, element.InnerText);
                    }
                }
            }*/
            dataList.Add(id, data);
        }
        
        Dictionary<string, Data> dataList = new Dictionary<string, Data>();

        void TryToLoad(string id) {
            try {<commit_msg>Updated ObjectLoader_File to use a named constant for the attributes file<commit_after>﻿// Copyright (C) 2007 <NAME>
// 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

using System;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using ICSharpCode.SharpZipLib.Zip;

namespace Core.GameObjects {
    /// <summary>
    /// Betöltő, amely merevlemezről tölti be a szükséges adatokat
    /// </summary>
    class ObjectLoader_File: ObjectLoader {
		const string AttributesFileName = "data.xml";
		
        class Data {
            internal Dictionary<string,string> attributes = new Dictionary<string,string>();
            internal Dictionary<string,MemoryStream> files = new Dictionary<string,MemoryStream>();
        }

        void LoadFromFile(string id) {
            string fileName = id.Replace('.', Path.DirectorySeparatorChar)+".kfiobject";
            Data data = new Data();
            using (ZipInputStream zs = new ZipInputStream(File.OpenRead(fileName))) {
                ZipEntry entry;
                while ((entry = zs.GetNextEntry()) != null) {
                    MemoryStream m = new MemoryStream();
                    int size = 2048;
                    byte[] buffer = new byte[size];
                    while ((size = zs.Read(buffer, 0, size)) > 0) {
                        m.Write(buffer, 0, size);
                    }
                    m.Position = 0;
                    data.files.Add(entry.Name, m);
                }
            }
            if (data.files.ContainsKey(AttributesFileName)) {
                XmlDocument doc = new XmlDocument();
                doc.Load(data.files[AttributesFileName]);
                XmlElement root = doc.DocumentElement;
                foreach(XmlNode element in root.ChildNodes) {
                    data.attributes.Add(element.Name, element.InnerText);
                }
            }
            /*foreach (KeyValuePair<string, MemoryStream> streams in data.files) {
                if (streams.Key == AttributesFileName) {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(streams.Value);
                    XmlElement root = doc.DocumentElement;
                    foreach(XmlNode element in root.ChildNodes) {
                        data.attributes.Add(element.Name, element.InnerText);
                    }
                }
            }*/
            dataList.Add(id, data);
        }
        
        Dictionary<string, Data> dataList = new Dictionary<string, Data>();

        void TryToLoad(string id) {
            try {
{'fraction_non_alphanumeric': 0.09517826291817183, 'fraction_numerical': 0.008481231349144023, 'mean_word_length': 1.8723500225529996, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3852468', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1547, 'n_words': 518}