Skip to content

Commit

Permalink
. added copy n paste to move files to another disks
Browse files Browse the repository at this point in the history
. added user option
. Release_v1_0.zip
  • Loading branch information
Augusto Baffa committed Dec 21, 2021
1 parent b5b3acd commit c137274
Show file tree
Hide file tree
Showing 8 changed files with 994 additions and 556 deletions.
Binary file added _release/Release_v1_0.zip
Binary file not shown.
23 changes: 20 additions & 3 deletions cpm_disk_manager/Disk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,23 @@ public List<FileEntry> GetFileEntries(String filename)
return file_entries[filename];
}

public List<FileEntry> GetFileEntry(string filename)
{
if (file_entries.ContainsKey(filename))
return file_entries[filename];
return null;
}


public void SetUser(string filename, int new_user)
{

for(int i = 0; i < file_entries[filename].Count; i++)
{
file_entries[filename][i]._status = new_user;
}
}

public byte[] GetFile(string filename)
{
int c = 0;
Expand Down Expand Up @@ -272,7 +289,7 @@ public List<short> GetFreeBlocks()
{
foreach (short s in fe._al)
{
if(s > 0)
if (s > 0)
used.Add(s);
}
}
Expand Down Expand Up @@ -305,13 +322,13 @@ public List<short> GetFreeDirEntries()
}
}
}

for (short i = 0; i <= drw; i++)
{
if (!used.Contains(i))
ret.Add(i);
}

return ret;
}
}
Expand Down
193 changes: 146 additions & 47 deletions cpm_disk_manager/DiskImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace cpm_disk_manager
{
Expand Down Expand Up @@ -33,7 +34,7 @@ public class DiskImage
public int DiskNumber { get { return this.disk_number; } }
public int DiskCount { get { return this.disk_count; } }

public DiskImageSize DiskImageSize {get;set;}
public DiskImageSize DiskImageSize { get; set; }



Expand Down Expand Up @@ -278,86 +279,184 @@ public bool cmd_rename(String filename, String newname)



public bool ReadImageFile(String fileName)
public void cmd_chuser(String filename, int newuser)
{
if (File.Exists(fileName))


disk.SetUser(filename, newuser);

foreach (FileEntry f in disk.GetFileEntries(filename))
{
FileInfo fi = new FileInfo(fileName);
Buffer.BlockCopy(f.GetDataEntry(), 0, fileData, disk_start + f._entry, 32);
}

DiskImageSize = fi.Length > 65000000 ? DiskImageSize._128MB : DiskImageSize._64MB;
disk.LoadDisk(fileData, disk_start);

}

fileData = new byte[fi.Length];

using (BinaryReader b = new BinaryReader(
File.Open(fileName, FileMode.Open)))

public bool ReadImageFile(String fileName, ToolStripProgressBar progressBar = null)
{
try
{
if (File.Exists(fileName))
{
// 2.
// Position and length variables.
int pos = 0;
// 2A.
// Use BaseStream.
int length = (int)b.BaseStream.Length;
while (pos < length)
FileInfo fi = new FileInfo(fileName);

DiskImageSize = fi.Length > 65000000 ? DiskImageSize._128MB : DiskImageSize._64MB;

fileData = new byte[fi.Length];

if (progressBar != null)
{
progressBar.Minimum = 0;
progressBar.Maximum = (int)fi.Length;
progressBar.Visible = true;
}


using (BinaryReader b = new BinaryReader(
File.Open(fileName, FileMode.Open)))
{
// 2.
// Position and length variables.
int pos = 0;
// 2A.
// Use BaseStream.
int length = (int)b.BaseStream.Length;
while (pos < length)
{

fileData[pos] = b.ReadByte();
// 3.
// Read integer.
//int v = b.ReadInt32();
//Console.WriteLine(v);

fileData[pos] = b.ReadByte();
// 3.
// Read integer.
//int v = b.ReadInt32();
//Console.WriteLine(v);
// 4.
// Advance our position variable.

// 4.
// Advance our position variable.
pos += sizeof(byte);
if (progressBar != null)
{
if (pos % 1000000 == 0)
{
progressBar.Value = pos;
Application.DoEvents();
}
}

pos += sizeof(byte);
}
}
}

disk_count = (int)Math.Ceiling((decimal)fileData.Length / 0x800000);
disk_start = disk_number * 0x800000;
if (disk_start == 0) disk_start = 0x4000;
if (progressBar != null)
progressBar.Visible = false;

this.UpdateDiskList();
return true;
disk_count = (int)Math.Ceiling((decimal)fileData.Length / 0x800000);
disk_start = disk_number * 0x800000;
if (disk_start == 0) disk_start = 0x4000;

this.UpdateDiskList();
return true;
}
}
catch
{
MessageBox.Show("An error occurred while reading the image file.\nPlease check the file.", "Reading Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

if (progressBar != null)
progressBar.Visible = false;

return false;
}


public bool SaveImageFile(string fileName)
public bool SaveImageFile(string fileName, ToolStripProgressBar progressBar = null)
{
using (BinaryWriter b = new BinaryWriter(File.Open(fileName, FileMode.Create)))
try
{
if (progressBar != null)
{
progressBar.Minimum = 0;
progressBar.Maximum = (int)fileData.Length;
progressBar.Visible = true;
}


using (BinaryWriter b = new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
for (int pos = 0; pos < fileData.Length; pos++)
{
b.Write(fileData[pos]);
if (progressBar != null)
{
if (pos % 1000000 == 0)
{
progressBar.Value = pos;
Application.DoEvents();
}
}
}
}


if (progressBar != null)
progressBar.Visible = false;

return true;

}
catch
{
for (int i = 0; i < fileData.Length; i++)
b.Write(fileData[i]);
MessageBox.Show("An error occurred while writing the image file.\nPlease check the file.", "Writing Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

return true;
if (progressBar != null)
progressBar.Visible = false;

return false;
}


public void ReadRawDisk(int selectedVol)
{
int clusters = DiskImageSize == DiskImageSize._64MB ? clusters_64mb : clusters_128mb;

using (RawDisk disk = new RawDisk(DiskNumberType.Volume, selectedVol, FileAccess.ReadWrite))
try
{
fileData = new byte[512 * clusters];
fileData = disk.ReadClusters(0, clusters);
}
int clusters = DiskImageSize == DiskImageSize._64MB ? clusters_64mb : clusters_128mb;

disk_count = (int)Math.Ceiling((decimal)fileData.Length / 0x800000);
disk_start = disk_number * 0x800000;
if (disk_start == 0) disk_start = 0x4000;
using (RawDisk disk = new RawDisk(DiskNumberType.Volume, selectedVol, FileAccess.ReadWrite))
{
fileData = new byte[512 * clusters];
fileData = disk.ReadClusters(0, clusters);
}

this.UpdateDiskList();
disk_count = (int)Math.Ceiling((decimal)fileData.Length / 0x800000);
disk_start = disk_number * 0x800000;
if (disk_start == 0) disk_start = 0x4000;

this.UpdateDiskList();

}
catch
{
MessageBox.Show("An error occurred while reading disk.", "Reading Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

public void WriteRawDisk(int selectedVol)
{
using (RawDisk disk = new RawDisk(DiskNumberType.Volume, selectedVol, FileAccess.ReadWrite))
try
{
disk.WriteClusters(fileData, 0);

using (RawDisk disk = new RawDisk(DiskNumberType.Volume, selectedVol, FileAccess.ReadWrite))
{
disk.WriteClusters(fileData, 0);
}
}
catch
{
MessageBox.Show("An error occurred while writing the disk.", "Writing Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cpm_disk_manager/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[assembly: AssemblyTitle("CP/M Disk Manager")]
[assembly: AssemblyDescription("CP/M Disk Manager")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("Baffasoft")]
[assembly: AssemblyProduct("CP/M Disk Manager")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
Expand Down
51 changes: 33 additions & 18 deletions cpm_disk_manager/frmEditFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void setFilename(String _filename)
{
filename = _filename;
}


public void newFile()
{
Expand Down Expand Up @@ -273,45 +273,60 @@ private void textBox1_DragEnter(object sender, DragEventArgs e)

private void textBox1_DragDrop(object sender, DragEventArgs e)
{

string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
try
{
if (File.Exists(file))
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
{
using (BinaryReader b = new BinaryReader(File.Open(file, FileMode.Open)))
if (File.Exists(file))
{
using (BinaryReader b = new BinaryReader(File.Open(file, FileMode.Open)))
{

//string filename = Path.GetFileName(file);
//string filename = Path.GetFileName(file);

current_data = Utils.ReadAllBytes(b);
current_data = Utils.ReadAllBytes(b);

if (original_data.LongLength == 0)
original_data = current_data;
if (original_data.LongLength == 0)
original_data = current_data;

set_entry();
calculate_checksum();
set_entry();
calculate_checksum();

}

}

}

}
catch
{
MessageBox.Show("An error occurred while reading the file.\nPlease check the file.", "Reading Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}

private void exportFileToolStripMenuItem_Click(object sender, EventArgs e)
{
Byte[] filearray = Utils.StringToByteArray(textBox1.Text);
saveFileDialog1.FileName = filename;
if (saveFileDialog1.ShowDialog(this) == DialogResult.OK)
try
{
string filename = saveFileDialog1.FileName;
Byte[] filearray = Utils.StringToByteArray(textBox1.Text);
saveFileDialog1.FileName = filename;
if (saveFileDialog1.ShowDialog(this) == DialogResult.OK)
{
string filename = saveFileDialog1.FileName;

File.WriteAllBytes(filename, filearray);
//MessageBox.Show("FileS, "Save Media", MessageBoxButtons.OK, MessageBoxIcon.Error);

File.WriteAllBytes(filename, filearray);
//MessageBox.Show("FileS, "Save Media", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}
catch
{
MessageBox.Show("An error occurred while writing the file.\nPlease check the file.", "Writing Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void numericUpDown1_ValueChanged(object sender, EventArgs e)
Expand Down
Loading

0 comments on commit c137274

Please sign in to comment.