Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag-Drop support to upload dump #104

Merged
merged 3 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions ChameleonMiniGUI/FrmMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions ChameleonMiniGUI/FrmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,37 @@ private void tfSerialHelp_TextClick(object sender, EventArgs e)
this.ActiveControl = tbSerialCmd;
}

private void tableLayoutPanel_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}

private void tableLayoutPanel_DragDrop(object sender, DragEventArgs e)
{
string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
if (s.Length > 0)
{
var dumpFileName = s[0];
if (File.Exists(dumpFileName))
{
// Get the tagslot index
var tagslotIndex = int.Parse(((TableLayoutPanel)sender).Name.Substring(((TableLayoutPanel)sender).Name.Length - 1));
if (tagslotIndex <= 0) return;

// Select the corresponding slot
SendCommandWithoutResult($"SETTING{_cmdExtension}={tagslotIndex - _tagslotIndexOffset}");

// Load the dump
UploadDump(dumpFileName);

// Refresh slot
RefreshSlot(tagslotIndex);
}
}
}
#endregion

#region Helper methods
Expand Down Expand Up @@ -2047,6 +2078,9 @@ internal void UploadDump(string filename)
{
var bytes = ReadFileIntoByteArray(filename);

// Try to identify the dump type
IndentifyDumpTypeBySize(bytes.Length);

var xmodem = new XMODEM(_comport, XMODEM.Variants.XModemChecksum);

SendCommandWithoutResult($"UPLOAD{_cmdExtension}");
Expand All @@ -2070,6 +2104,28 @@ internal void UploadDump(string filename)
}
}

private void IndentifyDumpTypeBySize(int byteLength)
{
switch (byteLength)
{
case 4096:
SendCommandWithoutResult($"CONFIG{_cmdExtension}=MF_CLASSIC_4K");
break;
case 64:
SendCommandWithoutResult($"CONFIG{_cmdExtension}=MF_ULTRALIGHT");
break;
case 80:
SendCommandWithoutResult($"CONFIG{_cmdExtension}=MF_ULTRALIGHT_EV1_80B");
break;
case 164:
SendCommandWithoutResult($"CONFIG{_cmdExtension}=MF_ULTRALIGHT_EV1_164B");
break;
default:
SendCommandWithoutResult($"CONFIG{_cmdExtension}=MF_CLASSIC_1K");
break;
}
}

internal void DownloadAndSaveDump(string filename)
{
// First get the current memory size of the slot
Expand Down