Пример #1
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            PuzzleType type = (PuzzleType)e.Argument;

            Assembly assembly   = Assembly.GetEntryAssembly();
            string   dataFolder = Path.GetDirectoryName(assembly.Location);

            dataFolder = Path.Combine(dataFolder, @"Data\Puzzle\" + PuzzleSetting.Instance.Type.ToString());

            DirectoryInfo di = null;

            if (!Directory.Exists(dataFolder))
            {
                di = Directory.CreateDirectory(dataFolder);
            }
            else
            {
                di = new DirectoryInfo(dataFolder);
            }

            FileInfo[] fis = di.GetFiles("*.pd");
            foreach (FileInfo fi in fis)
            {
                try
                {
                    PuzzleItem pi = PuzzleData.LoadPuzzleItem(fi.FullName);
                    if (pi.Type != type)
                    {
                        continue;
                    }
                    pi.ImageFile = fi.FullName;
                    worker.ReportProgress(0, pi);
                }
                catch (Exception ex)
                {
                    Debug.Assert(false, ex.Message);
                }
            }
        }
Пример #2
0
        public static PuzzleItem CreatePuzzle(string title, string imageFile, string creator)
        {
            PuzzleItem item = new PuzzleItem();

            item.Type            = PuzzleSetting.Instance.Type;
            item.TitleText       = title;
            item.DescriptionText = string.Empty;
            item.Creator         = creator;
            item.CreateDate      = DateTime.Now.ToUniversalTime();
            item.ThumbnailData   = GetThumbnailData(imageFile);
            item.ImageFile       = System.IO.Path.GetFileName(imageFile);

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(imageFile);
            MemoryStream          ms  = new MemoryStream();

            bmp.Save(ms, bmp.RawFormat);

            PuzzleData puzzleData = new PuzzleData(item, ms.ToArray());

            ms.Dispose();

            Assembly assembly   = Assembly.GetEntryAssembly();
            string   dataFolder = System.IO.Path.GetDirectoryName(assembly.Location);

            dataFolder = System.IO.Path.Combine(dataFolder, @"Data\Puzzle\" + PuzzleSetting.Instance.Type.ToString());
            if (!Directory.Exists(dataFolder))
            {
                Directory.CreateDirectory(dataFolder);
            }

            puzzleData.Save(System.IO.Path.Combine(dataFolder, item.Title + ".pd"));

            item.ImageFile = System.IO.Path.Combine(dataFolder, item.Title + ".pd");

            return(item);
        }