Beispiel #1
0
        /// <summary>
        /// Save all the dictionary to the specified chatlog file (in binary format).
        /// </summary>
        public void SaveToDat(String Path)
        {
            using (FileStream Stream = new FileStream(Path, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
            {
                Byte[]   Buffer   = new Byte[Kernel.MAX_BUFFER_SIZE];
                IntPtr[] Pointers = new IntPtr[0];

                lock (Entries)
                {
                    Pointers = new IntPtr[Entries.Count];
                    Entries.CopyTo(Pointers, 0);
                }

                Byte *pTemp = stackalloc Byte[MAX_TXTSIZE];
                for (Int32 i = 0; i < Pointers.Length; i++)
                {
                    ChatLogLine *pInfo = (ChatLogLine *)Pointers[i];

                    Kernel.memcpy(Buffer, pInfo->Sender, MAX_NAMESIZE);
                    Stream.Write(Buffer, 0, MAX_NAMESIZE);

                    Kernel.memcpy(pTemp, pInfo->Txt, MAX_TXTSIZE);
                    Encrypt(pTemp, MAX_TXTSIZE);

                    Kernel.memcpy(Buffer, pTemp, MAX_TXTSIZE);
                    Stream.Write(Buffer, 0, MAX_TXTSIZE);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Load the specified chatlog file (in binary format) into the dictionary.
        /// </summary>
        public void LoadFromDat(String Path)
        {
            Clear();

            lock (Entries)
            {
                using (FileStream Stream = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    Byte[] Buffer = new Byte[Kernel.MAX_BUFFER_SIZE];

                    while (true)
                    {
                        if (sizeof(ChatLogLine) != Stream.Read(Buffer, 0, sizeof(ChatLogLine)))
                        {
                            break;
                        }

                        ChatLogLine *pInfo = (ChatLogLine *)Kernel.malloc(sizeof(ChatLogLine));

                        Kernel.memcpy(pInfo, Buffer, sizeof(ChatLogLine));
                        Decrypt(pInfo->Txt, MAX_TXTSIZE);

                        Entries.Add((IntPtr)pInfo);
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Load the specified chatlog file (in custom plain format) into the dictionary.
        /// </summary>
        public void LoadFromTxt(String Path)
        {
            Clear();

            lock (Entries)
            {
                using (StreamReader Stream = new StreamReader(Path, Encoding.GetEncoding("Windows-1252")))
                {
                    String Line  = null;
                    Int32  LineC = 0;
                    while ((Line = Stream.ReadLine()) != null)
                    {
                        LineC++;

                        String[]     Parts = Line.Split('\t');
                        ChatLogLine *pInfo = (ChatLogLine *)Kernel.calloc(sizeof(ChatLogLine));

                        Byte[] Buffer = null;

                        try
                        {
                            Buffer = Encoding.GetEncoding("Windows-1252").GetBytes(Parts[0]);
                            Kernel.memcpy(pInfo->Sender, Buffer, MAX_NAMESIZE);

                            Buffer = Encoding.GetEncoding("Windows-1252").GetBytes(Parts[1]);
                            Kernel.memcpy(pInfo->Txt, Buffer, MAX_TXTSIZE);

                            Entries.Add((IntPtr)pInfo);
                        }
                        catch (Exception Exc)
                        {
                            Console.WriteLine("Error at line {0}.\n{1}", LineC, Exc);
                            Kernel.free(pInfo);
                        }
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Save all the dictionary to the specified chatlog file (in custom plain format).
        /// </summary>
        public void SaveToTxt(String Path)
        {
            using (StreamWriter Stream = new StreamWriter(Path, false, Encoding.GetEncoding("Windows-1252")))
            {
                IntPtr[] Pointers = new IntPtr[0];

                lock (Entries)
                {
                    Pointers = new IntPtr[Entries.Count];
                    Entries.CopyTo(Pointers, 0);
                }

                for (Int32 i = 0; i < Pointers.Length; i++)
                {
                    ChatLogLine *pInfo = (ChatLogLine *)Pointers[i];

                    StringBuilder Builder = new StringBuilder(Kernel.MAX_BUFFER_SIZE);
                    Builder.Append(Kernel.cstring(pInfo->Sender, MAX_NAMESIZE) + "\t");
                    Builder.Append(Kernel.cstring(pInfo->Txt, MAX_TXTSIZE));
                    Stream.WriteLine(Builder.ToString());
                }
            }
        }