public static void PackFile(FileInfo fi)
        {
            if (fi != null)
            {
                using (FileStream inFile = fi.OpenRead())
                {
                    if ((File.GetAttributes(fi.FullName)
                         & FileAttributes.Hidden)
                        != FileAttributes.Hidden & fi.Extension != ".gz")
                    {
                        using (FileStream outFile =
                                   File.Create(fi.FullName + ".gz"))
                        {
                            using (GZipStream Compress =
                                       new GZipStream(outFile,
                                                      CompressionMode.Compress))
                            {
                                inFile.CopyTo(Compress);

                                Console.WriteLine("Compressed {0} from {1} to {2} bytes.",
                                                  fi.Name, fi.Length.ToString(), outFile.Length.ToString());
                            }
                        }
                    }
                }
                NavigatorBoxControl.RefreshNaviBoxContent();
            }
            else
            {
                CustomDialog.ErrorMessage("Selection cannot be packed.", "Error");
            }
        }
        public static void UnpackFile(FileInfo fi)
        {
            if (fi != null)
            {
                using (FileStream inFile = fi.OpenRead())
                {
                    string curFile  = fi.FullName;
                    string origName = curFile.Remove(curFile.Length -
                                                     fi.Extension.Length);

                    using (FileStream outFile = File.Create(origName))
                    {
                        using (GZipStream Decompress = new GZipStream(inFile,
                                                                      CompressionMode.Decompress))
                        {
                            Decompress.CopyTo(outFile);

                            Console.WriteLine("Decompressed: {0}", fi.Name);
                        }
                    }
                }
                NavigatorBoxControl.RefreshNaviBoxContent();
            }
            else
            {
                CustomDialog.ErrorMessage("Selection is not packed.", "Error");
            }
        }
        private void NaviBoxEvent_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            string newName = CurrentDirectoryPath + e.Label;

            if (e.Label == null)
            {
                return;
            }
            ASCIIEncoding AE = new ASCIIEncoding();

            char[] temp = e.Label.ToCharArray();

            for (int x = 0; x < temp.Length; x++)
            {
                byte[] bc = AE.GetBytes(temp[x].ToString());

                if (bc[0] > 47 && bc[0] < 58)
                {
                    e.CancelEdit = true;
                    MessageBox.Show("The text for the item cannot contain numerical values.");
                    return;
                }
            }
            if (NavigatorBoxControl.IsItADirectory(NavigatorBoxControl.SelectionPath))
            {
                FileAndDirOperations.RenameDirectory(NavigatorBoxControl.SelectionPath, newName);
            }
            FileAndDirOperations.RenameFile(NavigatorBoxControl.SelectionPath, newName);
            NavigatorBoxControl.SelectionPath = newName;
        }
        private void NaviBoxEvent_DragDrop(object sender, DragEventArgs e)
        {
            if (NaviBox.SelectedItems.Count == 0)
            {
                return;
            }
            Point        cp         = NaviBox.PointToClient(new Point(e.X, e.Y));
            ListViewItem dragToItem = NaviBox.GetItemAt(cp.X, cp.Y);

            if (dragToItem == null)
            {
                return;
            }

            int dragIndex = dragToItem.Index;

            ListViewItem[] selection = new ListViewItem[NaviBox.SelectedItems.Count];

            for (int i = 0; i <= NaviBox.SelectedItems.Count - 1; i++)
            {
                selection[i] = NaviBox.SelectedItems[i];
            }
            for (int i = 0; i < selection.GetLength(0); i++)
            {
                ListViewItem dragItem  = selection[i];
                int          itemIndex = dragIndex;
                if (itemIndex == dragItem.Index)
                {
                    return;
                }
                if (dragItem.Index < itemIndex)
                {
                    itemIndex++;
                }
                else
                {
                    itemIndex = dragIndex + i;
                }
            }

            int targetIndex = NaviBox.InsertionMark.Index;

            if (targetIndex == -1)
            {
                return;
            }

            if (NaviBox.InsertionMark.AppearsAfterItem)
            {
                targetIndex++;
            }

            if (NavigatorBoxControl.IsItADirectory(NavigatorBoxControl.SelectionPath))
            {
                NavigatorBoxControl.CopyDirectory(NavigatorBoxControl.SelectionPath, NavigatorBoxControl.CopyTarget);
                return;
            }
            NavigatorBoxControl.CopyFile(NavigatorBoxControl.SelectionPath, NavigatorBoxControl.CopyTarget);
        }
 public static void DeleteFile(string path)
 {
     try
     {
         File.Delete(path);
     }
     catch { CustomDialog.ErrorMessage("Error: Access denied.", "Error"); }
     NavigatorBoxControl.RefreshNaviBoxContent();
 }
 public static void RenameDirectory(string oldName, string newName)
 {
     try
     {
         if (Directory.Exists(newName))
         {
             Directory.Delete(newName);
         }
         Directory.Move(oldName, newName);
         NavigatorBoxControl.RefreshNaviBoxContent();
     }
     catch { CustomDialog.ErrorMessage("Rename unsuccessful.", "Error"); }
 }
        public bool KeyPressed(Keys key)
        {
            if (key == Keys.Enter)
            {
                return(true);
            }

            if (key == Keys.Back)
            {
                NavigateOneDirectoryUp();
            }

            if (key == Keys.F2 && NaviBox.SelectedItems.Count > 0)
            {
                NaviBox.SelectedItems[0].BeginEdit();
            }

            if (key == Keys.F3)
            {
                FileAndDirOperations.PackFile(NavigatorBoxControl.MakeFileInfoFromPath());
            }

            if (key == Keys.F4)
            {
                FileAndDirOperations.UnpackFile(NavigatorBoxControl.MakeFileInfoFromPath());
            }

            if (key == Keys.F5)
            {
                NavigatorBoxControl.ShowFileProperties(NavigatorBoxControl.SelectionPath);
            }

            if (key == Keys.Delete)
            {
                if (NavigatorBoxControl.IsItADirectory(NavigatorBoxControl.SelectionPath))
                {
                    FileAndDirOperations.DeleteDirectory(NavigatorBoxControl.SelectionPath);
                }
                FileAndDirOperations.DeleteFile(NavigatorBoxControl.SelectionPath);
            }

            if (key == Keys.Escape)
            {
                Application.Exit();
            }
            return(false);
        }
        private void NaviBoxEvent_DragOver(object sender, DragEventArgs e)
        {
            Point targetPoint = NaviBox.PointToClient(new Point(e.X, e.Y));

            int targetIndex = NaviBox.InsertionMark.NearestIndex(targetPoint);

            if (targetIndex > -1)
            {
                Rectangle itemBounds = NaviBox.GetItemRect(targetIndex);
                if (targetPoint.X > itemBounds.Left + (itemBounds.Width / 2))
                {
                    NaviBox.InsertionMark.AppearsAfterItem = true;
                }
                else
                {
                    NaviBox.InsertionMark.AppearsAfterItem = false;
                }
            }
            NaviBox.InsertionMark.Index = targetIndex;
            // setting target path to the location of the cursor
            Point        cp         = NaviBox.PointToClient(new Point(e.X, e.Y));
            ListViewItem dragToItem = NaviBox.GetItemAt(cp.X, cp.Y);

            try
            {
                if (NavigatorBoxControl.IsItADirectory(NavigatorBoxControl.SelectionPath))
                {
                    DirectoryInfo srcDirInfo = new DirectoryInfo(NavigatorBoxControl.SelectionPath);
                    DirectoryInfo tarDirInfo = new DirectoryInfo(dragToItem.ListView.Columns[0].Text);
                    NavigatorBoxControl.CopyTarget = tarDirInfo.FullName + dragToItem.Text + @"\" + srcDirInfo.Name;
                }
                else
                {
                    FileInfo srcFileInfo = new FileInfo(NavigatorBoxControl.SelectionPath);
                    FileInfo tarFileInfo = new FileInfo(dragToItem.ListView.Columns[0].Text);
                    NavigatorBoxControl.CopyTarget = tarFileInfo.FullName + dragToItem.Text + @"\" + srcFileInfo.Name;
                }
            }
            catch { }
        }
 public void ChooseNavigateOrExecute()
 {
     CurrentSelection = new FileInfo(CurrentDirectoryPath + NaviBox.SelectedItems[0].Text);
     if (NavigatorBoxControl.IsItADirectory(CurrentSelection.FullName))
     {
         WillNavigateIntoDirectory(true);
         currentDirectoryInfo = new DirectoryInfo(CurrentDirectoryPath);
         ListContent();
     }
     else
     {
         currentDirectoryInfo = Directory.GetParent(CurrentDirectoryPath);
         try
         {
             Process.Start(CurrentSelection.FullName);
         }
         catch
         {
             CustomDialog.ErrorMessage("ERROR: Could not open file.", "Error");
         }
     }
 }
        private void RefreshNaviboxView()
        {
            int startingWidth = CalculateStartingWidth();

            foreach (NavigatorBox item in NavigatorBoxControl.naviBoxes)
            {
                item.NaviBox.Size     = new Size(ClientRectangle.Size.Width / NavigatorBoxControl.naviBoxes.Count, ClientRectangle.Size.Height - (NavigatorBoxControl.GetTaskbarHeight() + 10));
                item.NaviBox.Location = new Point(startingWidth, menuStrip1.Size.Height + 1);

                startingWidth = startingWidth + ClientRectangle.Size.Width / NavigatorBoxControl.naviBoxes.Count;

                int csw = item.NaviBox.ClientSize.Width;
                for (int i = 1; i < item.NaviBox.Columns.Count; i++)
                {
                    item.NaviBox.Columns[i].Width = -1;
                    csw -= item.NaviBox.Columns[i].Width;
                }

                item.NaviBox.Columns[0].Width = csw;
            }
        }
 private void decryptFileToolStripMenuItem_Click(object sender, EventArgs e)
 {
     NavigatorBoxControl.CheckIfDecryptable();
 }
 private void unpackToolStripMenuItem_Click(object sender, EventArgs e)
 {
     FileAndDirOperations.UnpackFile(NavigatorBoxControl.MakeFileInfoFromPath());
 }
 private void propertiesToolStripMenuItem_Click(object sender, EventArgs e)
 {
     NavigatorBoxControl.ShowFileProperties(NavigatorBoxControl.SelectionPath);
 }
 public void NavigateOneDirectoryUp()
 {
     WillNavigateIntoDirectory(false);
     CurrentDirectoryPath = currentDirectoryInfo.FullName + @"\";
     NavigatorBoxControl.RefreshNaviBoxContent();
 }
        public void ListContent()
        {
            List <FileSystemInfo> allItems = new List <FileSystemInfo>();

            // if GetSubdirectories of GetFiles return null, problems may happen. They should return an empty array I guess.
            allItems.AddRange(GetSubdirectories());
            allItems.AddRange(GetFiles());

            ClearContent();
            NaviBox.Columns[0].Text = CurrentDirectoryPath;

            if (CurrentDirectoryPath != @"C:\\")
            {
                NaviBox.Items.Add("..");
            }

            var imageList = new ImageList();

            NaviBox.SmallImageList = imageList;
            string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"..\..\Resources\");

            String[] ImageFiles = Directory.GetFiles(path);

            foreach (var file in ImageFiles)
            {
                //Add images to Imagelist
                imageList.Images.Add(Image.FromFile(file));
            }

            foreach (FileSystemInfo item in allItems)
            {
                string[] row = new string[4];
                row[0] = item.Name;

                Color backColor;
                int   imageIndex = 0;

                if (item.GetType().Equals(Type.GetType("System.IO.DirectoryInfo")))
                {
                    row[1] = "<DIR>";
                    string size = (String.Format("{0:N0} KB", NavigatorBoxControl.DirSize(new DirectoryInfo(item.FullName)) / 1024));
                    if (size != "0 KB")
                    {
                        row[2] = size;
                    }
                    else
                    {
                        row[2] = "Unknown";
                    }
                    row[3]     = item.LastWriteTime.ToShortDateString() + item.LastWriteTime.ToLongTimeString();
                    backColor  = Color.LightGoldenrodYellow;
                    imageIndex = 1;
                }
                else
                {
                    row[1]     = item.Extension.ToUpper();
                    row[2]     = String.Format("{0:N0} KB", NavigatorBoxControl.FileSize(new FileInfo(item.FullName)) / 1024);
                    row[3]     = item.CreationTime.ToShortDateString() + item.CreationTime.ToLongTimeString();
                    backColor  = Color.LightCyan;
                    imageIndex = 0;
                }
                ListViewItem listViewItem = new ListViewItem(row);
                listViewItem.BackColor  = backColor;
                listViewItem.ImageIndex = imageIndex;

                NaviBox.Items.Add(listViewItem);
            }

            NaviBox.Items[0].Selected = true;
            NaviBox.Items[0].Focused  = true;
        }