예제 #1
0
        /// <summary>
        /// load the maze from the disk
        /// </summary>
        /// <param name="filePath">path of the file</param>
        /// <param name="maze_name">name of the maze</param>
        public void LoadMazeFromDisk(string filePath, string maze_name)
        {
            string fullPath = filePath + maze_name;

            byte[]      byteFromFile     = new byte[100];
            List <byte> byteMazeFromFile = new List <byte>();

            using (Stream stream = new FileStream(fullPath, FileMode.Open))
            {
                using (Stream file_s = new MyCompressorStream(stream, 2))
                {
                    MyCompressorStream file_Str = file_s as MyCompressorStream;
                    int read_f = 0;
                    while ((read_f = file_Str.Read(byteFromFile, 0, 100)) != 0)
                    {
                        if (read_f < 100)
                        {
                            addToList(byteMazeFromFile, byteFromFile, read_f);
                        }
                        else
                        {
                            byteMazeFromFile.AddRange(byteFromFile);
                        }
                        byteFromFile = new byte[100];
                    }
                    byte[] b = byteMazeFromFile.ToArray();
                    m_DicOfMazes[maze_name] = new Maze3d(b);
                    file_Str.Flush();
                }
            }
        }
예제 #2
0
        private static void testCompression()
        {
            MyMaze3dGenerator smg = new MyMaze3dGenerator();
            Maze maze             = smg.generate(9, 6, 5);

            byte[] byets = ((Maze3d)maze).toByteArray();
            using (FileStream fileOutStream = new FileStream("1.maze", FileMode.Create))
            {
                using (MyCompressorStream outStream = new MyCompressorStream(fileOutStream, MyCompressorStream.Compress))
                {
                    outStream.Write(byets, 0, byets.Length);
                    outStream.Flush();
                }
            }
            byte[] mazeBytes;
            using (FileStream fileInStream = new FileStream("1.maze", FileMode.Open))
            {
                using (MyCompressorStream inStream = new MyCompressorStream(fileInStream, MyCompressorStream.Decompress))
                {
                    mazeBytes = new byte[byets.Length];
                    inStream.Read(mazeBytes, 0, mazeBytes.Length);
                }
            }
            Maze3d loadedMaze = new Maze3d(mazeBytes);

            Console.WriteLine(loadedMaze.equals(maze));

            Console.WriteLine("*******************************");
            Console.WriteLine("Press any key to continue");
            Console.WriteLine();
            Console.ReadKey();
        }
예제 #3
0
        /// <summary>
        /// Save Maze - Creates a compression of the maze and
        /// saves the file on the disk with a given file path
        /// </summary>
        /// <param name="mazeName">Maze name</param>
        /// <param name="path">File Name</param>
        /// <returns>True if successful saving the maze</returns>
        public bool saveMaze(string mazeName, string filePath)
        {
            //MessageBox.Show("save: " + mazeName);
            WinMaze winMaze     = m_currentWinMaze;
            Maze3d  currentMaze = winMaze.getMaze();

            add3dMaze(mazeName, currentMaze);
            if (isSolutionExists)
            {
                m_solutionsDictionary[mazeName] = mCurrentSolution;
            }

            if (currentMaze == null)
            {
                return(false);
            }
            using (FileStream fileOutStream = new FileStream(filePath, FileMode.Create))
            {
                using (Stream outStream = new MyCompressorStream(fileOutStream))
                {
                    outStream.Write(currentMaze.toByteArray(), 0, currentMaze.toByteArray().Length);
                    outStream.Flush();
                }
            }
            return(true);
        }
예제 #4
0
        /// <summary>
        /// save the maze to disk
        /// </summary>
        /// <param name="maze_name">name of the file</param>
        /// <param name="filePath">path of the file</param>
        public void SaveMazeToDisk(string maze_name, string filePath)
        {
            byte[] mazeToByte;
            string fullPath = filePath + maze_name;

            using (Stream stream = new FileStream(fullPath, FileMode.Create))
            {
                using (Stream file_s = new MyCompressorStream(stream, 1))
                {
                    MyCompressorStream file_Str = file_s as MyCompressorStream;
                    mazeToByte = ((Maze3d)(m_DicOfMazes[maze_name])).toByteArray();
                    file_Str.Write(mazeToByte, 0, mazeToByte.Length);
                    file_Str.Flush();
                }
            }
        }
예제 #5
0
파일: MyModel.cs 프로젝트: AdarOv/Maze
        /// <summary>
        /// Compress the maze 'mazeName' and save it into a file with a given path
        /// </summary>
        /// <param name="mazeName">the name of the maze to save</param>
        /// <param name="path">file path</param>
        /// <returns>true - for success, false for failure</returns>
        public bool saveMaze(string mazeName, string path)
        {
            Maze3d maze = retrieveMaze(mazeName);

            if (null == maze)
            {
                return(false);
            }
            using (FileStream fileOutStream = new FileStream(path, FileMode.Create))
            {
                using (Stream outStream = new MyCompressorStream(fileOutStream))
                {
                    outStream.Write(maze.toByteArray(), 0, maze.toByteArray().Length);
                    outStream.Flush();
                }
            }
            return(true);
        }
예제 #6
0
        private static void testMyCompressorStream()
        {
            Console.WriteLine("*******  testMyCompressorStream  *******\n");
            int[]          size3D          = { 3, 6, 7 }; // (z,y,x)
            IMazeGenerator mazeGenerator3d = new MyMaze3dGenerator();
            Maze3d         maze            = (Maze3d)mazeGenerator3d.generate(size3D);

            // save the maze to a file – compressed
            using (FileStream fileOutStream = new FileStream(@"D:\1.maze.txt", FileMode.Create))
            {
                using (Stream outStream = new MyCompressorStream(fileOutStream))
                {
                    outStream.Write(maze.toByteArray(), 0, maze.toByteArray().Length);
                    outStream.Flush();
                }
            }
            byte[] mazeBytes;
            using (FileStream fileInStream = new FileStream(@"D:\1.maze.txt", FileMode.Open))
            {
                using (Stream inStream = new MyCompressorStream(fileInStream))
                {
                    mazeBytes = new byte[maze.toByteArray().Length];
                    inStream.Read(mazeBytes, 0, mazeBytes.Length);
                }
            }
            Maze3d loadedMaze = new Maze3d(mazeBytes);

            Console.WriteLine("The original maze : ");
            maze.print();
            maze.getStartPosition().print();
            maze.getGoalPosition().print();

            Console.WriteLine("The decompress maze : ");
            loadedMaze.print();
            loadedMaze.getStartPosition().print();
            loadedMaze.getGoalPosition().print();
            Console.WriteLine(loadedMaze.Equals(maze));
        }
예제 #7
0
        /// <summary>
        /// Saves maze by name to a spesific path
        /// </summary>
        /// <param name="mazeName">maze name</param>
        /// <param name="path">path</param>
        public void SaveMaze(string mazeName, string path)
        {
            if (m_generatedMazes.ContainsKey(mazeName))
            {
                Maze3d maze = m_generatedMazes[mazeName];
                AddToSavedMazes(path, maze);//add the maze to the saved mazes Dictionary

                using (FileStream fileOutStream = new FileStream(path, FileMode.Create))
                {
                    using (Stream outStream = new MyCompressorStream(fileOutStream, ATP2016Library.Compression.CompressionMode.Compress))
                    {
                        outStream.Write(maze.toByteArray(), 0, maze.toByteArray().Length);
                        outStream.Flush();
                    }
                }

                ModelChanged("maze " + mazeName + " was saved in " + path);
            }
            else
            {
                ModelChanged("maze doesnt exist");
            }
        }