Esempio n. 1
0
        public static void HandleMove(object[] args)
        {
            FileManagerCommand command = (FileManagerCommand)args[1];
            bool   force = command == FileManagerCommand.ForceMoveFile;
            Guid   ID    = (Guid)args[2];
            string from  = (string)args[3];
            string to    = (string)args[4];

            NetworkHost.Send((byte)NetworkCommand.FileManager, (byte)FileManagerCommand.MoveResponce, ID, MiscHandler.MoveFile(from, to, force));
        }
Esempio n. 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // create instance
        FileManager fileManager = new FileManager();

        // set layouts
        fileManager.Height = 400;
        fileManager.Width  = 600;

        // add root directory
        RootDirectory rootDirectory = new RootDirectory();

        rootDirectory.DirectoryPath = DirectoryManager.GetRootDirectoryPath(Context);
        rootDirectory.Text          = "My Documents";
        fileManager.RootDirectories.Add(rootDirectory);

        fileManager.ExecuteCommand += FileManagerOnExecuteCommand;

        FileManagerCommand wyswygCmd = new FileManagerCommand();

        wyswygCmd.CommandName = "WYSWYG";
        wyswygCmd.Name        = "Edit with WYSWYG editor";

        FileManagerCommand editCmd = new FileManagerCommand();

        editCmd.CommandName = "EditText";
        editCmd.Name        = "Edit";

        FileType htmlFileType = new FileType();

        htmlFileType.Extensions    = "htm, html";
        htmlFileType.Name          = "HTML Document";
        htmlFileType.LargeImageUrl = "images/32x32/html.gif";
        htmlFileType.SmallImageUrl = "images/16x16/html.gif";
        htmlFileType.Commands.Add(wyswygCmd);
        htmlFileType.Commands.Add(editCmd);
        fileManager.FileTypes.Add(htmlFileType);

        FileType txtFileType = new FileType();

        txtFileType.Extensions = "txt, js, css";
        txtFileType.Name       = "HTML Document";
        txtFileType.Commands.Add(editCmd);
        fileManager.FileTypes.Add(txtFileType);

        PlaceHolder1.Controls.Add(fileManager);
    }
Esempio n. 3
0
 /// <summary>
 /// Composes remote path in FlashAir card inserting CGI command string.
 /// </summary>
 /// <param name="command">CGI command type</param>
 /// <param name="remotePath">Source remote path</param>
 /// <returns>Outcome remote path</returns>
 private static string ComposeRemotePath(FileManagerCommand command, string remotePath)
 {
     return(Settings.Current.RemoteRoot + _commandMap[command] + remotePath.TrimStart('/'));
 }
		/// <summary>
		/// Compose remote path in FlashAir card inserting CGI command string.
		/// </summary>
		/// <param name="command">CGI command type</param>
		/// <param name="remotePath">Source remote path</param>
		/// <returns>Outcome remote path</returns>
		private static string ComposeRemotePath(FileManagerCommand command, string remotePath)
		{
			return Settings.Current.RemoteRoot + _commandMap[command] + remotePath.TrimStart('/');
		}
Esempio n. 5
0
        public static void Handle(IClient c, object[] data)
        {
            FileManagerCommand command = (FileManagerCommand)data[1];

            if (command == FileManagerCommand.DownloadInvalid)
            {
                string downloadHandle = (string)data[2];
                if (!DownloadHandler.ContainsKey(downloadHandle))
                {
                    return;
                }
                MessageBox.Show("Download is invalid: \n" + (string)data[3]);
                DownloadHandler[downloadHandle].Stream.Close();
                DownloadHandler[downloadHandle].Stream.Dispose();
                DownloadHandler.Remove(downloadHandle);
            }

            if (command == FileManagerCommand.DownloadBlock)
            {
                string downloadHandle = (string)data[2];
                if (!DownloadHandler.ContainsKey(downloadHandle))
                {
                    return;
                }
                byte[] block      = (byte[])data[3];
                bool   finalBlock = (bool)data[4];
                DownloadHandler[downloadHandle].Stream.Write(block, 0, block.Length);
                if (finalBlock)
                {
                    DownloadHandler[downloadHandle].Stream.Close();
                    DownloadHandler[downloadHandle].Stream.Dispose();
                    DownloadHandler[downloadHandle].Stream = null;
                    MessageBox.Show(string.Format("Download Complete!\nLocation: {0}", DownloadHandler[downloadHandle].DownloadLocation));
                    DownloadHandler.Remove(downloadHandle);
                }
            }
            if (FormHandler.ContainsKey(c.ID))
            {
                Console.WriteLine("FM: {0}", command.ToString());
                if (command == FileManagerCommand.CopyResponce)
                {
                    FormHandler[c.ID].HandleCopyResponce((Guid)data[2], (bool)data[3]);
                }
                if (command == FileManagerCommand.MoveResponce)
                {
                    FormHandler[c.ID].HandleMoveResponce((Guid)data[2], (bool)data[3]);
                }
                if (command == FileManagerCommand.PropertiesResponce)
                {
                    FormHandler[c.ID].HandleProperties(data);
                }

                if (command == FileManagerCommand.DriveResponce)
                {
                    string[] drives      = (string[])data[2];
                    string[] driveSizes  = (string[])data[3];
                    string[] driveLabels = (string[])data[4];

                    FormHandler[c.ID].BeginUpdate(false, string.Empty);

                    for (int i = 0; i < drives.Length; i++)
                    {
                        FormHandler[c.ID].AddDrive(drives[i], driveSizes[i], driveLabels[i]);
                    }
                }
                if (command == FileManagerCommand.DirectoryResponce)
                {
                    string[] folders     = (string[])data[2];
                    bool[]   folderEmpty = (bool[])data[3];
                    string[] files       = (string[])data[4];
                    string[] filesizes   = (string[])data[5];

                    FormHandler[c.ID].BeginUpdate(true, (string)data[6]);

                    for (int i = 0; i < folders.Length; i++)
                    {
                        FormHandler[c.ID].AddDirectory(folders[i], folderEmpty[i]);
                    }

                    for (int i = 0; i < files.Length; i++)
                    {
                        FormHandler[c.ID].AddFile(files[i], filesizes[i]);
                    }
                }
                if (command == FileManagerCommand.Invalid)
                {
                    FormHandler[c.ID].BeginUpdate(true, (string)data[3]);
                    FormHandler[c.ID].InvalidDirectory((string)data[2]);
                }
            }
        }
Esempio n. 6
0
        public static void Handle(object[] data)
        {
            FileManagerCommand command = (FileManagerCommand)data[1];

            Console.WriteLine("File Manager: {0}", command.ToString());

            if (command == FileManagerCommand.ForceMoveFile || command == FileManagerCommand.MoveFile)
            {
                HandleMove(data);
            }
            if (command == FileManagerCommand.CopyFile)
            {
                HandleCopy(data);
            }
            if (command == FileManagerCommand.GetFileProperties)
            {
                GetFileProperties((Guid)data[2], (string)data[3]);
            }

            if (command == FileManagerCommand.StartDownload)
            {
                string handle = (string)data[2];
                string path   = (string)data[3];
                try
                {
                    using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                    {
                        if (fs.Length > 10000) //10kb
                        {
                            throw new Exception("File Too big");
                        }
                        byte[] buffer    = new byte[1000];
                        int    bytesread = 0;
                        while ((bytesread = fs.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            byte[] block = new byte[bytesread];
                            Buffer.BlockCopy(buffer, 0, block, 0, bytesread);
                            NetworkHost.Send((byte)NetworkCommand.FileManager, (byte)FileManagerCommand.DownloadBlock, handle, block, fs.Position == fs.Length);
                        }
                    }
                }
                catch (Exception ex)
                {
                    NetworkHost.Send((byte)NetworkCommand.FileManager, (byte)FileManagerCommand.DownloadInvalid, handle, ex.Message);
                }
            }

            if (command == FileManagerCommand.Update || command == FileManagerCommand.UpdateToSpecialFolder)
            {
                string path = string.Empty;
                if (command == FileManagerCommand.Update)
                {
                    path = (string)data[2];
                }
                if (command == FileManagerCommand.UpdateToSpecialFolder)
                {
                    path = Environment.GetFolderPath((Environment.SpecialFolder)data[2]);
                }


                if (path == string.Empty)
                {
                    DriveInfo[] driveArray  = DriveInfo.GetDrives();
                    string[]    drives      = new string[driveArray.Length];
                    string[]    DriveSizes  = new string[driveArray.Length];
                    string[]    DriveLabels = new string[driveArray.Length];

                    for (int i = 0; i < drives.Length; i++)
                    {
                        try
                        {
                            drives[i] = driveArray[i].Name;

                            if (driveArray[i].IsReady)
                            {
                                long   len = driveArray[i].TotalSize;
                                string ext = "b";
                                if ((len / 1000) > 0)
                                {
                                    len = len / 1000;
                                    ext = "KB";
                                    if ((len / 1000) > 0)
                                    {
                                        len = len / 1000;
                                        ext = "MB";
                                        if ((len / 1000) > 0)
                                        {
                                            len = len / 1000;
                                            ext = "GB";
                                            if ((len / 1000) > 0)
                                            {
                                                len = len / 1000;
                                                ext = "TB";
                                            }
                                        }
                                    }
                                }
                                DriveSizes[i]  = string.Format("{0} {1}", len, ext);
                                DriveLabels[i] = driveArray[i].VolumeLabel;
                            }
                            else
                            {
                                DriveLabels[i] = driveArray[i].DriveType.ToString();
                                DriveSizes[i]  = "";
                            }
                        }
                        catch (Exception ex)
                        {
                            drives[i]      = "Unknowen.";
                            DriveSizes[i]  = ex.Message;
                            DriveLabels[i] = "Error";
                        }
                    }
                    NetworkHost.Send((byte)NetworkCommand.FileManager, (byte)FileManagerCommand.DriveResponce, drives, DriveSizes, DriveLabels, path);
                }
                else
                {
                    try
                    {
                        DirectoryInfo   di    = new DirectoryInfo(path);
                        FileInfo[]      Files = di.GetFiles();
                        DirectoryInfo[] dirs  = di.GetDirectories();

                        string[] directoryNames = new string[dirs.Length];
                        bool[]   DirectroyEmpty = new bool[dirs.Length];
                        string[] filenames      = new string[Files.Length];
                        string[] filesizes      = new string[Files.Length];

                        for (int i = 0; i < directoryNames.Length; i++)
                        {
                            directoryNames[i] = dirs[i].Name;
                            try
                            {
                                DirectroyEmpty[i] = dirs[i].GetDirectories().Length < 1 && dirs[i].GetFiles().Length < 1; //Need to improve this
                            }
                            catch
                            {
                                DirectroyEmpty[i] = true;
                            }
                        }
                        for (int i = 0; i < filenames.Length; i++)
                        {
                            filenames[i] = Files[i].Name;
                            long   len = Files[i].Length;
                            string ext = "b";
                            if ((len / 1000) > 0)
                            {
                                len = len / 1000;
                                ext = "KB";
                                if ((len / 1000) > 0)
                                {
                                    len = len / 1000;
                                    ext = "MB";
                                    if ((len / 1000) > 0)
                                    {
                                        len = len / 1000;
                                        ext = "GB";
                                    }
                                }
                            }
                            filesizes[i] = string.Format("{0} {1}", len, ext);
                        }

                        NetworkHost.Send((byte)NetworkCommand.FileManager, (byte)FileManagerCommand.DirectoryResponce, directoryNames, DirectroyEmpty, filenames, filesizes, path);
                    }
                    catch (Exception ex)
                    {
                        NetworkHost.Send((byte)NetworkCommand.FileManager, (byte)FileManagerCommand.Invalid, ex.Message, path);
                    }
                }
            }
        }