Пример #1
0
        public void SerializeObject5(string fileName, SerializableObject5 objToSerialize)
        {
            FileStream      fstream         = File.Open(fileName, FileMode.Create);
            BinaryFormatter binaryFormatter = new BinaryFormatter();

            binaryFormatter.Serialize(fstream, objToSerialize);
            fstream.Close();
        }
Пример #2
0
        private void changeDirectory(string path)
        {
            if (currDirIno == -1)
            {
                //заполнение рута
                SerializableObject5 obj5 = new SerializableObject5();
                obj5.Roots = roots;
                MySerializer5 serializer5 = new MySerializer5();
                serializer5.SerializeObject5("Roots.txt", obj5);
            }
            else
            {
                save_file_binary(currDirIno, serializeDirectory(roots));
            }

            //открываем рут он же корень
            SerializableObject5 obj        = new SerializableObject5();
            MySerializer5       serializer = new MySerializer5();

            obj.Roots = roots;
            obj       = serializer.DeserializeObject5("Roots.txt");
            roots     = obj.Roots;

            if (path == "/")
            {
                currDir = "/";
                return;
            }

            String[] filenames = path.Trim('/').Split('/');
            if (filenames.Length > 0)
            {
                int err = openDirectory(filenames[0]);

                if (err == -9)
                {
                    changeDirectory(currDir);
                    return;
                }

                if (filenames.Length > 1)
                {
                    for (int i = 1; i < filenames.Length; i++)
                    {
                        save_file_binary(currDirIno, serializeDirectory(roots));
                        err = openDirectory(filenames[i]);

                        if (err == -9)
                        {
                            changeDirectory(currDir);
                            return;
                        }
                    }
                }
            }

            currDir = path;
        }
Пример #3
0
        public SerializableObject5 DeserializeObject5(string fileName)
        {
            SerializableObject5 objToSerialize  = null;
            FileStream          fstream         = File.Open(fileName, FileMode.Open);
            BinaryFormatter     binaryFormatter = new BinaryFormatter();

            objToSerialize = (SerializableObject5)binaryFormatter.Deserialize(fstream);
            fstream.Close();
            return(objToSerialize);
        }
Пример #4
0
        public Boolean open()
        {
            Main.roots.Clear();
            Main.inodes.Clear();
            Main.bitcard.Clear();
            try
            {
                //открываем суперблок
                BinaryFormatter Formatter = new BinaryFormatter();
                FileStream      File      = new FileStream("SuperBlock.txt", FileMode.Open);
                Main.Super1 = (SuperBlock)Formatter.Deserialize(File);
                File.Close();

                //открываем иноды
                SerializableObject1 obj1        = new SerializableObject1();
                MySerializer1       serializer1 = new MySerializer1();
                obj1.Inodes = Main.inodes;
                obj1        = serializer1.DeserializeObject1("Inodes.txt");
                Main.inodes = obj1.Inodes;

                //открываем битовую карту
                SerializableObject2 obj2        = new SerializableObject2();
                MySerializer2       serializer2 = new MySerializer2();
                obj2.Bitcard = Main.bitcard;
                obj2         = serializer2.DeserializeObject2("Bitcard.txt");
                Main.bitcard = obj2.Bitcard;

                //достаем пользователей
                SerializableObject obj = new SerializableObject();
                obj.Users = Main.users;
                MySerializer serializer = new MySerializer();
                obj        = serializer.DeserializeObject("Users.txt");
                Main.users = obj.Users;

                //открываем рут он же корень
                SerializableObject5 obj5        = new SerializableObject5();
                MySerializer5       serializer5 = new MySerializer5();
                obj5.Roots = Main.roots;
                obj5       = serializer5.DeserializeObject5("Roots.txt");
                Main.roots = obj5.Roots;
                return(true);
            }
            catch (FileNotFoundException e)
            {
                MessageBox.Show("Система повреждена! Обратитесь к администратору!", "Аларма");
                return(false);
            }
        }
Пример #5
0
        private void btnEnd_Click(object sender, EventArgs e)
        {
            BinaryFormatter Formatter = new BinaryFormatter();
            FileStream      File      = new FileStream("SuperBlock.txt", FileMode.Create);

            Formatter.Serialize(File, Main.Super1);      //сериализация
            File.Close();

            //форматируем Inode, Bitcard
            SerializableObject1 obj1 = new SerializableObject1();

            obj1.Inodes = Main.inodes;
            MySerializer1 serializer1 = new MySerializer1();

            serializer1.SerializeObject1("Inodes.txt", obj1);

            SerializableObject2 obj2 = new SerializableObject2();

            obj2.Bitcard = Main.bitcard;
            MySerializer2 serializer2 = new MySerializer2();

            serializer2.SerializeObject2("Bitcard.txt", obj2);

            if (Main.currDir == "/")
            {
                //заполнение рута
                SerializableObject5 obj5 = new SerializableObject5();
                obj5.Roots = Main.roots;
                MySerializer5 serializer5 = new MySerializer5();
                serializer5.SerializeObject5("Roots.txt", obj5);
            }
            else
            {
                Main.save_file_binary(Main.currDirIno, Main.serializeDirectory(Main.roots));
            }

            //форматируем пользователей.
            SerializableObject obj = new SerializableObject();

            obj.Users = Main.users;
            MySerializer serializer = new MySerializer();

            serializer.SerializeObject("Users.txt", obj);

            this.Hide();
        }
Пример #6
0
        private void exit(object sender, EventArgs e)
        {
            if (vhod == 1)
            {
                BinaryFormatter Formatter = new BinaryFormatter();
                FileStream      File      = new FileStream("SuperBlock.txt", FileMode.Create);
                Formatter.Serialize(File, Super1);      //сериализация
                File.Close();

                //форматируем Inode, Bitcard
                SerializableObject1 obj1 = new SerializableObject1();
                obj1.Inodes = inodes;
                MySerializer1 serializer1 = new MySerializer1();
                serializer1.SerializeObject1("Inodes.txt", obj1);

                SerializableObject2 obj2 = new SerializableObject2();
                obj2.Bitcard = bitcard;
                MySerializer2 serializer2 = new MySerializer2();
                serializer2.SerializeObject2("Bitcard.txt", obj2);

                if (currDir == "/")
                {
                    //заполнение рута
                    SerializableObject5 obj5 = new SerializableObject5();
                    obj5.Roots = roots;
                    MySerializer5 serializer5 = new MySerializer5();
                    serializer5.SerializeObject5("Roots.txt", obj5);
                }
                else
                {
                    save_file_binary(currDirIno, serializeDirectory(roots));
                }

                //форматируем пользователей.
                SerializableObject obj = new SerializableObject();
                obj.Users = users;
                MySerializer serializer = new MySerializer();
                serializer.SerializeObject("Users.txt", obj);
            }
            Environment.Exit(0);
        }
        private void listuser(object sender, EventArgs e)
        {
            BinaryFormatter Formatter = new BinaryFormatter();
            FileStream      File      = new FileStream("SuperBlock.txt", FileMode.Create);

            Formatter.Serialize(File, Main.Super1);      //сериализация
            File.Close();

            //форматируем Inode, Bitcard
            SerializableObject1 obj1 = new SerializableObject1();

            obj1.Inodes = Main.inodes;
            MySerializer1 serializer1 = new MySerializer1();

            serializer1.SerializeObject1("Inodes.txt", obj1);

            SerializableObject2 obj2 = new SerializableObject2();

            obj2.Bitcard = Main.bitcard;
            MySerializer2 serializer2 = new MySerializer2();

            serializer2.SerializeObject2("Bitcard.txt", obj2);

            if (Main.currDir == "/")
            {
                //заполнение рута
                SerializableObject5 obj5 = new SerializableObject5();
                obj5.Roots = Main.roots;
                MySerializer5 serializer5 = new MySerializer5();
                serializer5.SerializeObject5("Roots.txt", obj5);
            }
            else
            {
                Main.save_file_binary(Main.currDirIno, Main.serializeDirectory(Main.roots));
            }

            //форматируем пользователей.
            SerializableObject obj = new SerializableObject();

            obj.Users = Main.users;
            MySerializer serializer = new MySerializer();

            serializer.SerializeObject("Users.txt", obj);

            ListViewItem item;

            listView1.Items.Clear();
            foreach (User user in Main.users)
            {
                if (user.Login != "**********")
                {
                    string itog, uid, name, status;
                    string isAdmin = user.isAdmin.ToString();
                    uid = Convert.ToString(user.UID);

                    name = user.Login;
                    item = new ListViewItem(uid);
                    item.SubItems.Add(name);
                    item.SubItems.Add(isAdmin);
                    listView1.Items.Add(item);
                }
            }
        }
Пример #8
0
        public void formating()
        {
            //чистим списки
            Main.users.Clear();
            Main.roots.Clear();
            Main.inodes.Clear();
            Main.bitcard.Clear();
            BinaryFormatter Formatter = new BinaryFormatter();

            //форматируем суперблок
            Main.Super1.s_type  = "S5FS";
            Main.Super1.s_fsize = 36864;
            Main.Super1.s_bsize = 4096;
            FileStream File = new FileStream(@"SuperBlock.txt", FileMode.Create);

            Formatter.Serialize(File, Main.Super1);
            File.Close();

            //форматируем Inode, Bitcard
            bool[]   lis         = { true, true, true, true };
            DateTime Time_create = DateTime.Now;
            DateTime Time_modify = DateTime.Now;

            for (int i = 0; i < Main.Super1.s_fsize; i++)
            {
                Inode TestInode1 = new Inode(i, -1, lis, -1, Time_create, Time_modify, new int[] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, false, false);
                Main.inodes.Add(TestInode1);
                Main.bitcard.Add(false);
            }
            SerializableObject1 obj1 = new SerializableObject1();

            obj1.Inodes = Main.inodes;
            MySerializer1 serializer1 = new MySerializer1();

            serializer1.SerializeObject1(@"Inodes.txt", obj1);
            SerializableObject2 obj2 = new SerializableObject2();

            obj2.Bitcard = Main.bitcard;
            MySerializer2 serializer2 = new MySerializer2();

            serializer2.SerializeObject2(@"Bitcard.txt", obj2);

            //форматируем пользователей
            User TestUser = new User(0, "admin", Main.GetHashString("admin"), 1);

            Main.users.Add(TestUser);
            string log = "**********";
            string pas = Main.GetHashString("**********");

            for (int i = 1; i <= 49; i++)
            {
                User TestUser1 = new User(i, log, pas, 0);
                Main.users.Add(TestUser1);
            }
            SerializableObject obj = new SerializableObject();

            obj.Users = Main.users;
            MySerializer serializer = new MySerializer();

            serializer.SerializeObject(@"Users.txt", obj);

            //Заполнение места для информации
            File = new FileStream("Data.txt", FileMode.Create);
            File.Seek(Main.Super1.s_fsize * Main.Super1.s_bsize, SeekOrigin.Begin);
            byte[] ar = new byte[3];
            File.Write(ar, 0, 3);
            File.Close();

            //заполнение корневого каталога
            string name1 = "^^^^^^^^";

            for (int i = 0; i < Main.Super1.s_fsize; i++)
            {
                Root Root1 = new Root(i, name1);
                Main.roots.Add(Root1);
            }
            SerializableObject5 obj5 = new SerializableObject5();

            obj5.Roots = Main.roots;
            MySerializer5 serializer5 = new MySerializer5();

            serializer5.SerializeObject5(@"Roots.txt", obj5);

            MessageBox.Show("Форматирование завершено.");
        }