Skip to content

Commit 0d04f52

Browse files
committed
Updates and missing giles
1 parent 9a53c8d commit 0d04f52

File tree

8 files changed

+1654
-0
lines changed

8 files changed

+1654
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/ArduinoFloppyReader/lib.backup
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Microsoft Visual C++ generated resource script.
2+
//
3+
#include "resource.h"
4+
5+
#define APSTUDIO_READONLY_SYMBOLS
6+
/////////////////////////////////////////////////////////////////////////////
7+
//
8+
// Generated from the TEXTINCLUDE 2 resource.
9+
//
10+
#include "winres.h"
11+
12+
/////////////////////////////////////////////////////////////////////////////
13+
#undef APSTUDIO_READONLY_SYMBOLS
14+
15+
/////////////////////////////////////////////////////////////////////////////
16+
// English (United Kingdom) resources
17+
18+
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
19+
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
20+
#pragma code_page(1252)
21+
22+
#ifdef APSTUDIO_INVOKED
23+
/////////////////////////////////////////////////////////////////////////////
24+
//
25+
// TEXTINCLUDE
26+
//
27+
28+
1 TEXTINCLUDE
29+
BEGIN
30+
"resource.h\0"
31+
END
32+
33+
2 TEXTINCLUDE
34+
BEGIN
35+
"#include ""winres.h""\r\n"
36+
"\0"
37+
END
38+
39+
3 TEXTINCLUDE
40+
BEGIN
41+
"\r\n"
42+
"\0"
43+
END
44+
45+
#endif // APSTUDIO_INVOKED
46+
47+
48+
/////////////////////////////////////////////////////////////////////////////
49+
//
50+
// Version
51+
//
52+
53+
VS_VERSION_INFO VERSIONINFO
54+
FILEVERSION 2,8,9,0
55+
PRODUCTVERSION 2,8,9,0
56+
FILEFLAGSMASK 0x3fL
57+
#ifdef _DEBUG
58+
FILEFLAGS 0x1L
59+
#else
60+
FILEFLAGS 0x0L
61+
#endif
62+
FILEOS 0x40004L
63+
FILETYPE 0x1L
64+
FILESUBTYPE 0x0L
65+
BEGIN
66+
BLOCK "StringFileInfo"
67+
BEGIN
68+
BLOCK "080904b0"
69+
BEGIN
70+
VALUE "CompanyName", "RobSmithDev"
71+
VALUE "FileDescription", "DrawBridge aka Arduino Floppy Disk Reader and Writer Windows App"
72+
VALUE "FileVersion", "2.8.9.0"
73+
VALUE "InternalName", "DrawBridge.exe"
74+
VALUE "LegalCopyright", "Copyright � 2017-2024 Robert Smith, All rights reserved. "
75+
VALUE "OriginalFilename", "DrawBridge.exe"
76+
VALUE "ProductName", "DawBridge aka Arduino Floppy Disk Reader/Writer"
77+
VALUE "ProductVersion", "2.8.9.0"
78+
END
79+
END
80+
BLOCK "VarFileInfo"
81+
BEGIN
82+
VALUE "Translation", 0x809, 1200
83+
END
84+
END
85+
86+
87+
/////////////////////////////////////////////////////////////////////////////
88+
//
89+
// Icon
90+
//
91+
92+
// Icon with lowest ID value placed first to ensure application icon
93+
// remains consistent on all systems.
94+
IDR_MAINFRAME ICON "res\\ArduinoFloppyReaderConsole.ico"
95+
96+
#endif // English (United Kingdom) resources
97+
/////////////////////////////////////////////////////////////////////////////
98+
99+
100+
101+
#ifndef APSTUDIO_INVOKED
102+
/////////////////////////////////////////////////////////////////////////////
103+
//
104+
// Generated from the TEXTINCLUDE 3 resource.
105+
//
106+
107+
108+
/////////////////////////////////////////////////////////////////////////////
109+
#endif // not APSTUDIO_INVOKED
110+
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/* DrawBridge - aka ArduinoFloppyReader (and writer)
2+
*
3+
* Copyright (C) 2017-2024 Robert Smith (@RobSmithDev)
4+
* https://amiga.robsmithdev.co.uk
5+
*
6+
* This file is multi-licensed under the terms of the Mozilla Public
7+
* License Version 2.0 as published by Mozilla Corporation and the
8+
* GNU General Public License, version 2 or later, as published by the
9+
* Free Software Foundation.
10+
*
11+
* MPL2: https://www.mozilla.org/en-US/MPL/2.0/
12+
* GPL2: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
13+
*
14+
*/
15+
16+
#include "stdafx.h"
17+
#include "ArduinoFloppyReaderWin.h"
18+
#include "CCleanDialog.h"
19+
#include "afxdialogex.h"
20+
21+
22+
23+
// CCleanDialog dialog
24+
25+
IMPLEMENT_DYNAMIC(CCleanDialog, CDialogEx)
26+
27+
CCleanDialog::CCleanDialog(const std::wstring& comPort) : m_comPort(comPort), CDialogEx(IDD_CLEAN) {
28+
}
29+
30+
CCleanDialog::~CCleanDialog()
31+
{
32+
if (m_iothread) {
33+
if (m_iothread->joinable()) m_iothread->join();
34+
delete m_iothread;
35+
m_iothread = nullptr;
36+
}
37+
}
38+
39+
void CCleanDialog::DoDataExchange(CDataExchange* pDX)
40+
{
41+
CDialogEx::DoDataExchange(pDX);
42+
DDX_Control(pDX, IDC_MAKEYOUROWN, m_makeYourOwn);
43+
DDX_Control(pDX, ID_START, m_startButton);
44+
DDX_Control(pDX, 1007, m_progress);
45+
}
46+
47+
48+
BEGIN_MESSAGE_MAP(CCleanDialog, CDialogEx)
49+
ON_WM_SYSCOMMAND()
50+
ON_MESSAGE(WM_USER, &CCleanDialog::OnUser)
51+
ON_BN_CLICKED(ID_CLOSE, &CCleanDialog::OnBnClickedClose)
52+
ON_STN_CLICKED(IDC_MAKEYOUROWN, &CCleanDialog::OnStnClickedMakeyourown)
53+
ON_WM_SETCURSOR()
54+
ON_WM_CTLCOLOR()
55+
ON_BN_CLICKED(ID_START, &CCleanDialog::OnBnClickedStart)
56+
END_MESSAGE_MAP()
57+
58+
void CCleanDialog::resetProgress(int max) {
59+
if (m_spTaskbarList) m_spTaskbarList->SetProgressState(GetSafeHwnd(), TBPF_INDETERMINATE);
60+
m_maxValue = max;
61+
m_stateNeedsToChange = true;
62+
};
63+
64+
void CCleanDialog::setProgress(int position) {
65+
m_progress.SetPos(position);
66+
if (m_stateNeedsToChange) {
67+
m_stateNeedsToChange = false;
68+
if (m_spTaskbarList) m_spTaskbarList->SetProgressState(GetSafeHwnd(), TBPF_NORMAL);
69+
}
70+
if (m_spTaskbarList) m_spTaskbarList->SetProgressValue(GetSafeHwnd(), position, m_maxValue);
71+
};
72+
73+
// CCleanDialog message handlers
74+
BOOL CCleanDialog::OnInitDialog()
75+
{
76+
BOOL ret = CDialogEx::OnInitDialog();
77+
78+
HRESULT hr = ::CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, __uuidof(ITaskbarList3), reinterpret_cast<void**>(&m_spTaskbarList));
79+
if (SUCCEEDED(hr)) m_spTaskbarList->HrInit(); else m_spTaskbarList = nullptr;
80+
81+
resetProgress(100);
82+
83+
return ret;
84+
}
85+
86+
87+
BOOL CCleanDialog::PreTranslateMessage(MSG* pMsg)
88+
{
89+
if (pMsg->message == WM_KEYDOWN)
90+
{
91+
if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE)
92+
{
93+
return !m_iothread; // Do not process further
94+
}
95+
}
96+
97+
if (pMsg->message == WM_CLOSE) {
98+
if (m_iothread) return 1;
99+
}
100+
101+
return CWnd::PreTranslateMessage(pMsg);
102+
}
103+
104+
105+
void CCleanDialog::OnSysCommand(UINT nID, LPARAM lParam)
106+
{
107+
if ((nID & 0xFFF0) == SC_CLOSE)
108+
{
109+
if (m_iothread) return;
110+
}
111+
112+
CDialogEx::OnSysCommand(nID, lParam);
113+
}
114+
115+
afx_msg LRESULT CCleanDialog::OnUser(WPARAM wParam, LPARAM lParam)
116+
{
117+
if (wParam == 100) {
118+
if (lParam == 2) MessageBox(_T("No disk was detected in the drive. Clean aborted."), _T("Sorry"), MB_OK | MB_ICONEXCLAMATION); else
119+
if (lParam == 1) MessageBox(_T("Unable to communicate with the COM port. Please check port or run diagnostics."), _T("Sorry"), MB_OK | MB_ICONEXCLAMATION); else
120+
if (m_abortPressed) CDialogEx::OnCancel(); else MessageBox(L"Cleaning cycle completed.", L"Drive Head Cleaner", MB_OK | MB_ICONINFORMATION);
121+
if (m_iothread) {
122+
if (m_iothread->joinable()) m_iothread->join();
123+
delete m_iothread;
124+
m_iothread = nullptr;
125+
}
126+
127+
m_startButton.EnableWindow(true);
128+
}
129+
return 0;
130+
}
131+
132+
133+
void CCleanDialog::OnBnClickedClose() {
134+
if (m_iothread) m_abortPressed = true; else CDialogEx::OnCancel();
135+
}
136+
137+
138+
void CCleanDialog::OnStnClickedMakeyourown()
139+
{
140+
ShellExecute(GetSafeHwnd(), L"OPEN", L"https://youtu.be/7E4fSypg0pk", NULL, NULL, SW_SHOW);
141+
}
142+
143+
144+
BOOL CCleanDialog::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
145+
{
146+
if (pWnd->GetSafeHwnd() == m_makeYourOwn.GetSafeHwnd()) {
147+
SetCursor(LoadCursor(NULL, IDC_HAND));
148+
return TRUE;
149+
}
150+
return CDialogEx::OnSetCursor(pWnd, nHitTest, message);
151+
}
152+
153+
154+
HBRUSH CCleanDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
155+
{
156+
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
157+
158+
if (nCtlColor == CTLCOLOR_STATIC && pWnd->GetSafeHwnd() == m_makeYourOwn.GetSafeHwnd()) pDC->SetTextColor(GetSysColor(COLOR_HOTLIGHT));
159+
return hbr;
160+
}
161+
162+
void CCleanDialog::OnBnClickedStart()
163+
{
164+
if (m_iothread) return;
165+
m_startButton.EnableWindow(false);
166+
167+
if (m_iothread) {
168+
if (m_iothread->joinable()) m_iothread->join();
169+
delete m_iothread;
170+
m_iothread = nullptr;
171+
}
172+
173+
m_iothread = new std::thread([this]() {
174+
175+
resetProgress(1000);
176+
setProgress(0);
177+
178+
ArduinoFloppyReader::ADFWriter reader;
179+
180+
if (reader.openDevice(m_comPort)) {
181+
bool noDisk = reader.runClean([this](const uint16_t position, const uint16_t maxPosition) -> bool {
182+
if (position == 0) resetProgress(maxPosition);
183+
setProgress(position);
184+
return !m_abortPressed;
185+
}) == ArduinoFloppyReader::ADFResult::adfrCompletedWithErrors;
186+
reader.closeDevice();
187+
PostMessage(WM_USER, 100, noDisk?2:0);
188+
} else PostMessage(WM_USER, 100, 1);
189+
});
190+
191+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#pragma once
2+
3+
/* DrawBridge - aka ArduinoFloppyReader (and writer)
4+
*
5+
* Copyright (C) 2017-2024 Robert Smith (@RobSmithDev)
6+
* https://amiga.robsmithdev.co.uk
7+
*
8+
* This file is multi-licensed under the terms of the Mozilla Public
9+
* License Version 2.0 as published by Mozilla Corporation and the
10+
* GNU General Public License, version 2 or later, as published by the
11+
* Free Software Foundation.
12+
*
13+
* MPL2: https://www.mozilla.org/en-US/MPL/2.0/
14+
* GPL2: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
15+
*
16+
*/
17+
18+
#include "afxwin.h"
19+
#include "afxcmn.h"
20+
#include <thread>
21+
#include <string>
22+
#include "resource.h"
23+
#include <functional>
24+
#include "../lib/ArduinoInterface.h"
25+
#include "../lib/ADFWriter.h"
26+
27+
// CCleanDialog dialog
28+
29+
class CCleanDialog : public CDialogEx
30+
{
31+
DECLARE_DYNAMIC(CCleanDialog)
32+
33+
private:
34+
std::thread* m_iothread = nullptr;
35+
bool m_abortPressed = false;
36+
bool m_stateNeedsToChange = false;
37+
int m_maxValue = 100;
38+
const std::wstring m_comPort;
39+
40+
CComPtr<ITaskbarList3> m_spTaskbarList;
41+
public:
42+
CCleanDialog(const std::wstring& m_comPort);
43+
virtual ~CCleanDialog();
44+
45+
// Dialog Data
46+
#ifdef AFX_DESIGN_TIME
47+
enum { IDD = IDD_CLEAN };
48+
#endif
49+
50+
protected:
51+
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
52+
53+
DECLARE_MESSAGE_MAP()
54+
55+
public:
56+
virtual BOOL OnInitDialog();
57+
virtual BOOL PreTranslateMessage(MSG* pMsg);
58+
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
59+
60+
public:
61+
bool wasAbortPressed() const { return m_abortPressed; };
62+
void resetProgress(int max);
63+
void setProgress(int position);
64+
protected:
65+
afx_msg LRESULT OnUser(WPARAM wParam, LPARAM lParam);
66+
public:
67+
68+
afx_msg void OnBnClickedClose();
69+
afx_msg void OnStnClickedMakeyourown();
70+
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
71+
CStatic m_makeYourOwn;
72+
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
73+
afx_msg void OnBnClickedStart();
74+
CButton m_startButton;
75+
CProgressCtrl m_progress;
76+
};

0 commit comments

Comments
 (0)