Beispiel #1
0
        static public void SaveFile(string name, byte[] data, int offset, int size)
        {
            IO io = FileCreate(name);

            try
            {
                io.Write(data, offset, size);
            }
            finally
            {
                io.Close();
            }
        }
Beispiel #2
0
        public static int GetFileSize(string name)
        {
            IO io = IO.FileOpen(name, false);

            try
            {
                return(io.FileSize);
            }
            finally
            {
                io.Close();
            }
        }
Beispiel #3
0
        static public byte[] ReadFile(string name)
        {
            IO io = FileOpen(name);

            try
            {
                int    size = io.FileSize;
                byte[] ret  = io.Read(size);
                return(ret);
            }
            finally
            {
                io.Close();
            }
        }
Beispiel #4
0
        static void deleteUnusedTempDir()
        {
            DirEntry[] files;

            files = IO.EnumDir(Env.tempDir);

            foreach (DirEntry e in files)
            {
                if (e.IsFolder)
                {
                    if (e.FileName.StartsWith("NET_", StringComparison.CurrentCultureIgnoreCase) && e.FileName.Length == 8)
                    {
                        string dirFullName  = Path.Combine(Env.tempDir, e.fileName);
                        string lockFileName = Path.Combine(dirFullName, "LockFile.dat");
                        bool   deleteNow    = false;

                        try
                        {
                            IO io = IO.FileOpen(lockFileName);
                            io.Close();

                            try
                            {
                                io        = IO.FileOpen(lockFileName, true);
                                deleteNow = true;
                                io.Close();
                            }
                            catch
                            {
                            }
                        }
                        catch
                        {
                            DirEntry[] files2;

                            deleteNow = true;

                            try
                            {
                                files2 = IO.EnumDir(dirFullName);

                                foreach (DirEntry e2 in files2)
                                {
                                    if (e2.IsFolder == false)
                                    {
                                        string fullPath = Path.Combine(dirFullName, e2.fileName);

                                        try
                                        {
                                            IO io2 = IO.FileOpen(fullPath, true);
                                            io2.Close();
                                        }
                                        catch
                                        {
                                            deleteNow = false;
                                        }
                                    }
                                }
                            }
                            catch
                            {
                                deleteNow = false;
                            }
                        }

                        if (deleteNow)
                        {
                            IO.DeleteDir(dirFullName, true);
                        }
                    }
                }
            }
        }
Beispiel #5
0
        void init(string filename)
        {
            filename = IO.InnerFilePath(filename);
            string filenameOnly = Path.GetFileName(filename);
            string filenameAlt  = Path.Combine(Path.GetDirectoryName(filename), "_" + filenameOnly);

            try
            {
                IO.FileReplaceRename(filenameAlt, filename);
            }
            catch
            {
            }

            list = new Dictionary <string, HamCoreEntry>();

            try
            {
                hamcore_io = IO.FileOpen(filename);
            }
            catch
            {
                return;
            }

            try
            {
                byte[] header  = hamcore_io.Read(HamcoreHeaderSize);
                byte[] header2 = Str.AsciiEncoding.GetBytes(HamcoreHeaderData);
                if (header == null || Util.CompareByte(header, header2) == false)
                {
                    throw new SystemException();
                }

                uint   num = 0;
                byte[] buf = hamcore_io.Read(Util.SizeOfInt32);
                num = Util.ByteToUInt(buf);
                uint i;
                for (i = 0; i < num; i++)
                {
                    uint str_size;

                    buf      = hamcore_io.Read(Util.SizeOfInt32);
                    str_size = Util.ByteToUInt(buf);
                    if (str_size >= 1)
                    {
                        str_size--;
                    }

                    byte[] str_data = hamcore_io.Read((int)str_size);
                    string tmp      = Str.ShiftJisEncoding.GetString(str_data);

                    HamCoreEntry c = new HamCoreEntry();
                    c.FileName = tmp;

                    buf    = hamcore_io.Read(Util.SizeOfInt32);
                    c.Size = Util.ByteToUInt(buf);

                    buf = hamcore_io.Read(Util.SizeOfInt32);
                    c.SizeCompressed = Util.ByteToUInt(buf);

                    buf      = hamcore_io.Read(Util.SizeOfInt32);
                    c.Offset = Util.ByteToUInt(buf);

                    list.Add(c.FileName.ToUpper(), c);
                }
            }
            catch
            {
                hamcore_io.Close();
            }
        }