Skip to content

Commit 2c0ace7

Browse files
committed
add: add todsk option to save the hfe converted into a dsk image file
1 parent 000aa59 commit 2c0ace7

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

cli/action/dsk.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ func (a *Action) DoDskActions() (onError bool, message, hint string) {
236236
}
237237
for _, action := range a.tasks.a {
238238
switch action.a {
239+
case ActionConvertHFEToDSK:
240+
onError, message, hint = SaveDsk(a.d, action.File)
239241
case ActionFormatDsk:
240242
onError, message, hint = FormatDsk(a.Path, a.desc, a.options.vendorFormat, a.options.dataFormat, a.options.force)
241243
case ActionDisplayHexaFileDsk:
@@ -801,6 +803,18 @@ func OpenDsk(osFile string, desc DskDescriptor, quiet bool) (d dsk.DSK, onError
801803
return d, false, "", ""
802804
}
803805

806+
func SaveDsk(d dsk.DSK, osFile string) (onError bool, message, hint string) {
807+
f, err := os.Create(osFile)
808+
if err != nil {
809+
return true, fmt.Sprintf("Error while write file (%s) error %v\n", osFile, err), "Check your dsk file path."
810+
}
811+
defer f.Close()
812+
if err := d.Write(f); err != nil {
813+
return true, fmt.Sprintf("Error while write file (%s) error %v\n", osFile, err), "Check your input file"
814+
}
815+
return false, "", ""
816+
}
817+
804818
func FileinfoDsk(d dsk.DSK, fileInDsk string) (onError bool, message, hint string) {
805819
if fileInDsk == "" {
806820
return true, "amsdosfile option is empty, set it.", "usage sample : dsk -dsk output.dsk hello.bin -info "

cli/action/dsk_action.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var (
1818
ActionRawImportDsk DskTask = "rawimport"
1919
ActionFileinfoDsk DskTask = "info"
2020
ActionHFEFileinfoDsk DskTask = "hfe"
21+
ActionConvertHFEToDSK DskTask = "todsk"
2122
)
2223

2324
type DskTaskFile struct {
@@ -129,3 +130,10 @@ func (a *DskTasks) WithActionHFEFile(path string, isSet bool) *DskTasks {
129130
}
130131
return a
131132
}
133+
134+
func (a *DskTasks) WithActionConvertHFEToDSK(path string, isSet bool) *DskTasks {
135+
if isSet {
136+
a.a = append(a.a, DskTaskFile{File: path, a: ActionConvertHFEToDSK})
137+
}
138+
return a
139+
}

cli/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ var (
5050
hidden = flag.Bool("hide", false, "Hide the imported file")
5151
removeHeader = flag.Bool("removeheader", false, "Remove amsdos header from exported file")
5252
hfeFilepath = flag.String("hfe", "", "Path to the HFE file to handle.")
53+
toDsk = flag.String("todsk", "", "Convert the specified HFE file to DSK format.")
5354

5455
appVersion = "0.37"
5556
version = flag.Bool("version", false, "Display the application version and exit.")
@@ -96,7 +97,8 @@ func main() {
9697
WithActionRawImportDsk(*dskPath, *rawimport).
9798
WithActionFileinfoDsk(*dskPath, *info != "").
9899
WithActionGetAllFileDsk(*autoextract, *autoextract != "").
99-
WithActionHFEFile(*hfeFilepath, *hfeFilepath != "")
100+
WithActionHFEFile(*hfeFilepath, *hfeFilepath != "").
101+
WithActionConvertHFEToDSK(*toDsk, *toDsk != "")
100102

101103
desc := action.NewDskDescriptor().
102104
WithSector(*sector).

0 commit comments

Comments
 (0)