Esempio n. 1
0
        void UpdateDir(uint dirID)
        {
            string          command   = "SELECT id, parent_id, name, modified_date FROM directorys_info WHERE parent_id = " + dirID.ToString() + ";";
            MySqlCommand    commander = new MySqlCommand(command, connection);
            MySqlDataReader reader    = commander.ExecuteReader();

            while (reader.Read())
            {
                Directory_Info dir = new Directory_Info();
                dir.id        = (uint)reader["id"];
                dir.parent_id = (uint)reader["parent_id"];
                dir.name      = (string)reader["name"];
                dir.modDate   = ((DateTime)reader["modified_date"]).ToString();
                socket.CryptoSend(BlindNetUtil.StructToByte(dir), PacketType.Sending);
            }
            reader.Close();
            socket.CryptoSend(null, PacketType.EOF);

            command   = "SELECT id, name, modified_date, UPPER(type), size FROM files_info WHERE dir_id = " + dirID.ToString() + ";";
            commander = new MySqlCommand(command, connection);
            reader    = commander.ExecuteReader();
            while (reader.Read())
            {
                File_Info file = new File_Info();
                file.id      = (uint)reader["id"];
                file.name    = (string)reader["name"];
                file.modDate = reader["modified_date"].ToString();
                file.type    = (string)reader["UPPER(type)"];
                file.size    = (uint)reader["size"];
                socket.CryptoSend(BlindNetUtil.StructToByte(file), PacketType.Sending);
            }
            reader.Close();
            socket.CryptoSend(null, PacketType.EOF);
        }
Esempio n. 2
0
        void UpdateRoot()
        {
            if (!connection.Ping())
            {
                Console.WriteLine("ERROR : [UID : " + uid + "] Database connection is terminate");
                return;
            }

            SetAccessibleDirs();
            if (accessibleDirs.Length < 1)
            {
                socket.CryptoSend(null, PacketType.EOF);
                return;
            }

            string          command   = "SELECT id, parent_id, name FROM directorys_info WHERE id IN (" + UintArrToString(accessibleDirs) + ");";
            MySqlCommand    commander = new MySqlCommand(command, connection);
            MySqlDataReader reader    = commander.ExecuteReader();

            while (reader.Read())
            {
                Directory_Info dir = new Directory_Info();
                dir.id        = (uint)reader["id"];
                dir.parent_id = (uint)reader["parent_id"];
                dir.name      = (string)reader["name"];
                socket.CryptoSend(BlindNetUtil.StructToByte(dir), PacketType.Sending);
            }
            reader.Close();
            socket.CryptoSend(null, PacketType.EOF);
        }
Esempio n. 3
0
        private void ChangeNameDir(Directory_Info dir)
        {
            string       command   = "UPDATE directorys_info SET name = '" + dir.name + "' WHERE id = " + dir.id + ";";
            MySqlCommand commander = new MySqlCommand(command, connection);

            UpdateModDate(dir.parent_id);

            if (commander.ExecuteNonQuery() == 1)
            {
                socket.CryptoSend(null, PacketType.OK);
            }
            else
            {
                socket.CryptoSend(null, PacketType.Fail);
            }
        }
Esempio n. 4
0
        void AddDir(Directory_Info dir)
        {
            try
            {
                string       command   = "INSERT INTO directorys_info values(0, '" + dir.name + "', " + dir.parent_id + ", DEFAULT, NULL);";
                MySqlCommand commander = new MySqlCommand(command, connection);
                if (commander.ExecuteNonQuery() != 1)
                {
                    socket.CryptoSend(null, PacketType.Fail);
                }

                commander.CommandText = "SELECT MAX(id) FROM directorys_info;";
                MySqlDataReader reader = commander.ExecuteReader();
                reader.Read();
                dir.id = (uint)reader["MAX(id)"];
                reader.Close();

                commander.CommandText = "SELECT path FROM directorys_info WHERE id = " + dir.parent_id + ";";
                reader = commander.ExecuteReader();
                reader.Read();
                string path = (string)reader["path"] + dir.id;
                reader.Close();

                commander.CommandText = "UPDATE directorys_info SET path = '" + RemakePath(path, true) + "' WHERE id = " + dir.id + ";";
                if (commander.ExecuteNonQuery() != 1)
                {
                    socket.CryptoSend(null, PacketType.Fail);
                }

                DirectoryInfo di = new DirectoryInfo(path);
                if (di.Exists)
                {
                    socket.CryptoSend(null, PacketType.Fail);
                    return;
                }
                UpdateModDate(dir.parent_id);

                di.Create();
                socket.CryptoSend(BlindNetUtil.StructToByte(dir), PacketType.OK);
                logger.Log(LogRank.INFO, "Created directory(" + dir.id + ")");
            }
            catch
            {
                socket.CryptoSend(null, PacketType.Fail);
            }
        }
Esempio n. 5
0
        private void FileUpload(Directory_Info dir)
        {
            File_Info file = BlindNetUtil.ByteToStruct <File_Info>(socket.CryptoReceiveMsg());

            Debug.WriteLine("Start FileUpload \"{0}\"", file.name);
            MySqlCommand commander = null;

            try
            {
                string           command = "SELECT path FROM files_info WHERE dir_id = " + dir.id + " AND name = '" + file.name + "';";
                MySqlDataAdapter adapter = new MySqlDataAdapter(command, connection);
                DataSet          dataset = new DataSet();
                adapter.Fill(dataset);
                string path = null;

                if (dataset.Tables[0].Rows.Count != 0)
                {
                    command   = "UPDATE files_info SET modified_date = NOW() WHERE dir_id = " + dir.id + " AND name = '" + file.name + "';";
                    commander = new MySqlCommand(command, connection);
                    if (commander.ExecuteNonQuery() != 1)
                    {
                        throw new Exception();
                    }

                    path = (string)dataset.Tables[0].Rows[0]["path"];
                    File.Delete(path);
                }
                else
                {
                    command = "INSERT INTO files_info VALUES (" + 0 + ", " + dir.id + ", '" + file.name + "', DEFAULT, UPPER('" + file.type + "'), " +
                              file.size + ", NULL);";
                    commander = new MySqlCommand(command, connection);
                    if (commander.ExecuteNonQuery() != 1)
                    {
                        throw new Exception();
                    }
                }

                Debug.WriteLine("[FileUpload] Start leceiving");
                byte[] data = socket.CryptoReceiveMsg();
                Debug.WriteLine("[FileUpload] End leceiving {0} bytes", data.Length);

                command   = "SELECT MAX(id) FROM files_info;";
                commander = new MySqlCommand(command, connection);
                MySqlDataReader reader = commander.ExecuteReader();
                reader.Read();
                file.id = (uint)reader["MAX(id)"];
                reader.Close();

                if (path == null)
                {
                    command = "SELECT path FROM directorys_info WHERE id = " + dir.id + ";";
                    adapter = new MySqlDataAdapter(command, connection);
                    adapter.Fill(dataset);
                    if (dataset.Tables[0].Rows.Count != 1)
                    {
                        throw new Exception();
                    }

                    path      = (string)dataset.Tables[0].Rows[0]["path"] + file.id + ".blind";
                    command   = "UPDATE files_info SET path = '" + RemakePath(path, false) + "' WHERE dir_id = " + dir.id + " AND name = '" + file.name + "';";
                    commander = new MySqlCommand(command, connection);
                    if (commander.ExecuteNonQuery() != 1)
                    {
                        throw new Exception();
                    }
                }

                data = EncryptFile(data);
                if (data == null)
                {
                    throw new Exception();
                }
                data = BlindNetUtil.MergeArray(BitConverter.GetBytes(file.id), data);

                FileInfo   fi = new FileInfo(path);
                FileStream fs = fi.OpenWrite();
                fs.Write(data, 0, data.Length);
                fs.Close();

                UpdateModDate(dir.id);
                socket.CryptoSend(null, PacketType.OK);
                logger.Log(LogRank.INFO, "Uploaded file(" + file.id + ")");
            }
            catch (Exception ex)
            {
                socket.CryptoSend(null, PacketType.Fail);
            }
        }