
// HDDImgMakerDlg.h : файл заголовка
//

#pragma once
#include "afxwin.h"
#include "Ini.h"

#define SECTOR_SIZE 512
#define SECTOR_SIZEW 256

typedef union
{
	BYTE b[SECTOR_SIZE];
	WORD w[SECTOR_SIZEW];
} USector;

#pragma pack(push)
#pragma pack(1)
struct SYS_SECTOR
{
	WORD main_config;   //0
	WORD cylinders;     //1
	WORD reserved2;     //2
	WORD heads;         //3
	WORD raw_bytes_per_track; //4
	WORD raw_bytes_per_sector; //5
	WORD sectors;       //6
	WORD reserved7[3];  //7,8,9
	BYTE serial_number[20]; //10
	WORD buffer_type;   //20
	WORD buffer_size_in_sectors;    //21
	WORD ecc_bytes_num; //22
	BYTE fw_version[8]; //23
	BYTE model_name[40]; //27
	WORD word47;        //47
	WORD word48;        //48
	WORD capabilities1; //49
	WORD capabilities2; //50
	WORD reserved51[6]; //51
	DWORD capacity_in_sectors; //57,58
	WORD reserved59;    //59
	DWORD total_used_sectors; //60,61
	WORD reserved62[194]; //62
};
#pragma pack(pop)

// диалоговое окно CHDDImgMakerDlg
class CHDDImgMakerDlg : public CDialogEx
{
		CString m_strImgName;
		CString m_strExistingImgName;
		CString m_strModelName;
		CString m_strSerialNumber;
		CString m_strAppPath;
		CString m_strExistingImgPath;
		int m_nCylinders;
		int m_nHeads;
		int m_nSectors;
		bool m_bCancel;
		bool m_bConvert;
		CSpinButtonCtrl m_spinCylinders;
		CSpinButtonCtrl m_spinHeads;
		CSpinButtonCtrl m_spinSectors;
		CProgressCtrl m_progress;
		CComboBox m_TypeCombo;

		CFile m_file;
		CFile m_fileExisting;

		CIni m_Ini;

// Создание
	public:
		CHDDImgMakerDlg(CWnd *pParent = nullptr);  // стандартный конструктор

// Данные диалогового окна
		enum { IDD = IDD_HDDIMGMAKER_DIALOG };

	protected:
		virtual void DoDataExchange(CDataExchange *pDX) override;    // поддержка DDX/DDV


// Реализация
	protected:
		HICON m_hIcon;
		void OutByteSize();
		void _UpdateData();
		void CopyString2Sys(BYTE *dst, const CString &str, int max_len);
		void AnalyseExistingImage(CFile *pFile);
		void InverseBuf(USector &buf);
		void EnableGeometryChange(bool bEnable);
		void ChangeMakeButtonText();
		void ChangeFormatExistingImage();
		void WorkHDI(int nTotalSectors);
		void WorkHDIX(int nTotalSectors);
		// Созданные функции схемы сообщений
		virtual BOOL OnInitDialog() override;
		afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
		afx_msg void OnPaint();
		afx_msg HCURSOR OnQueryDragIcon();
		afx_msg void OnEnChangeEditCylinders();
		afx_msg void OnEnChangeEditHeads();
		afx_msg void OnEnChangeEditSectors();
		afx_msg void OnBnClickedButtonSernumber();
		afx_msg void OnBnClickedButtonBrowse();
		afx_msg void OnBnClickedButtonBrowseExisting();
		afx_msg void OnBnClickedButtonMake();
		afx_msg void OnEnKillfocusEditImgname();
		afx_msg void OnEnKillfocusEditExistingImgname();
		afx_msg void OnEnKillfocusEditSectors();
		afx_msg void OnEnSetfocusEditSectors();
		afx_msg void OnEnKillfocusEditHeads();
		afx_msg void OnEnSetfocusEditHeads();
		afx_msg void OnEnKillfocusEditCylinders();
		afx_msg void OnEnSetfocusEditCylinders();
		afx_msg void OnBnClickedButtonHdi2img();
		DECLARE_MESSAGE_MAP()

};
