Skip to content

Commit

Permalink
Optimize File Writes and add Free Space info on status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
LuigiBlood committed May 24, 2020
1 parent d420abd commit d561b42
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
22 changes: 14 additions & 8 deletions mfs_gui/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum cliptype
{
Copy, Cut
}

MFSDirectory current_dir;
MFSFile[] clipboardfiles;
cliptype clipboardtype;
Expand Down Expand Up @@ -59,6 +60,7 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e)
clipboardfiles = null;
this.Text = "64DD MFS Manager";
}
UpdateStatusBar();
}
}

Expand Down Expand Up @@ -114,10 +116,7 @@ private void listView_DragEnter(object sender, DragEventArgs e)
private void listView_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
{
Program.AddFileToDirectory(current_dir, file);
}
Program.AddFilesToDirectory(current_dir, files);
UpdateTreeView(current_dir);
}

Expand Down Expand Up @@ -152,10 +151,7 @@ private void importToolStripMenuItem_Click(object sender, EventArgs e)
if (ofs.ShowDialog() == DialogResult.OK)
{
string[] files = ofs.FileNames;
foreach (string file in files)
{
Program.AddFileToDirectory(current_dir, file);
}
Program.AddFilesToDirectory(current_dir, files);
UpdateTreeView(current_dir);
}
}
Expand Down Expand Up @@ -278,6 +274,16 @@ private void UpdateTreeView(MFSDirectory dir)
{
listView.Items.AddRange(items);
}
UpdateStatusBar();
}

private void UpdateStatusBar()
{
statusStrip1.Items.Clear();
if (Program.IsDiskLoaded())
{
statusStrip1.Items.Add("Free Space: " + Math.Floor((Program.GetCapacitySize() - Program.GetUsedSpaceSize()) / 100000f) / 10f + " MB");
}
}
}
}
26 changes: 23 additions & 3 deletions mfs_gui/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,21 @@ public static bool AddFileToDirectory(MFSDirectory dir, string filepath)
FileStream file = new FileStream(filepath, FileMode.Open);
byte[] filedata = new byte[file.Length];
file.Read(filedata, 0, (int)file.Length);

MFSRAMUtil.WriteFile(disk, filedata, Path.GetFileName(filepath), dir.DirectoryID);

file.Close();

return MFSRAMUtil.WriteFile(disk, filedata, Path.GetFileName(filepath), dir.DirectoryID);
}

public static bool AddFilesToDirectory(MFSDirectory dir, string[] filepaths)
{
foreach (string file in filepaths)
{
if (Program.AddFileToDirectory(dir, file) == false)
{
MessageBox.Show("Could not import " + Path.GetFileName(file) + "\nCancelling file import.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
}
}
return true;
}

Expand Down Expand Up @@ -217,5 +227,15 @@ public static bool MoveFiles(MFSFile[] files, ushort dir)

return true;
}

public static int GetCapacitySize()
{
return MFSRAMUtil.GetCapacitySize(disk);
}

public static int GetUsedSpaceSize()
{
return MFSRAMUtil.GetTotalUsedSize(disk);
}
}
}
18 changes: 18 additions & 0 deletions mfs_manager/MFS/MFSUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,24 @@ public static int GetFreeSpaceSize(MFSDisk mfsDisk)
return unused;
}

public static int GetCapacitySize(MFSDisk mfsDisk)
{
int totalsize = 0;
for (int i = 6; i < Leo.SIZE_LBA - Leo.RamStartLBA[mfsDisk.RAMVolume.DiskType]; i++)
{
switch (mfsDisk.RAMVolume.FAT[i])
{
case (ushort)MFS.FAT.Prohibited:
case (ushort)MFS.FAT.DontManage:
break;
default:
totalsize += Leo.LBAToByte(mfsDisk.RAMVolume.DiskType, Leo.RamStartLBA[mfsDisk.RAMVolume.DiskType] + i, 1);
break;
}
}
return totalsize;
}

// As there can be multiple files with the same name, it is preferable to input a parent Directory ID.
public static bool CheckIfFileAlreadyExists(MFSDisk mfsDisk, string _filename, ushort _dir = 0xFFFF)
{
Expand Down

0 comments on commit d561b42

Please sign in to comment.