Ejemplo n.º 1
0
        /// <summary>
        /// Temp文件夹下唯一的新建临时文件夹,末尾包括\
        /// </summary>
        /// <returns>结果</returns>
        public static string TempRandomPath()
        {
            string path = FileEx.TempFileName(false);

            Directory.CreateDirectory(path);
            return(path.DealPath());
        }
Ejemplo n.º 2
0
        public Gif(string fileName)
        {
            timer       = new Timer();
            timer.Tick += Timer_Tick;

            if (FileEx.Exists(fileName))
            {
                Image = Image.FromFile(fileName);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 压缩数组
        /// </summary>
        /// <param name="input">数组</param>
        /// <returns>结果</returns>
        public static byte[] Compress(byte[] input)
        {
            string filename   = FileEx.TempFileName();
            string filename7z = FileEx.TempFileName();

            File.WriteAllBytes(filename, input);
            ZipFile(filename, filename7z);
            byte[] bts = File.ReadAllBytes(filename7z);
            FileEx.TryDelete(filename);
            FileEx.TryDelete(filename7z);
            return(bts);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 解压缩数组
        /// </summary>
        /// <param name="input">数组</param>
        /// <returns>结果</returns>
        public static byte[] Decompress(byte[] input)
        {
            string zipfile = FileEx.TempFileName();

            File.WriteAllBytes(zipfile, input);

            string unzipDir = DirEx.TempRandomPath();

            UnZipFile(zipfile, unzipDir);
            string[] fall      = Directory.GetFiles(unzipDir, "*.*", SearchOption.TopDirectoryOnly);
            string   unzipfile = fall[0];

            byte[] bts = File.ReadAllBytes(unzipfile);
            FileEx.TryDelete(unzipfile);
            FileEx.TryDelete(zipfile);
            DirEx.TryDelete(unzipDir);
            return(bts);
        }
Ejemplo n.º 5
0
        public MMFile(string mapName, int capacity = 4096)
        {
            if (!FileEx.IsValidFileName(mapName))
            {
                throw new Exception("MapName is not valid.");
            }

            MapName     = mapName;
            WorkerDelay = 10;
            Capacity    = Math.Max(4096, capacity);

            var mmf = MemoryMappedFile.CreateOrOpen(MapName, Capacity, MemoryMappedFileAccess.ReadWrite);

            using (var accessor = mmf.CreateViewAccessor(0, Capacity))
            {
                var value = accessor.ReadBoolean(0);
                if (!value)
                {
                    accessor.Write(0, false);
                }
            }
        }