Skip to content

Commit

Permalink
When adding file(s) delete if it exists (confirmation dialog bog is a…
Browse files Browse the repository at this point in the history
…lso provided by TC, so we have clearance to delete)
  • Loading branch information
ggnkua committed May 16, 2023
1 parent b84fdfc commit c1be29d
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 12 deletions.
4 changes: 3 additions & 1 deletion dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,8 @@ int Pack(char *PackedFile, char *SubPath, char *SrcPath, char *AddList, int Flag
return E_ECREATE;
}

// TODO: Check if path exists before creating

// Create the directory entry in the parent directory
time_t ltime;
time(&ltime); // Get current date/time
Expand Down Expand Up @@ -1602,7 +1604,7 @@ int Pack(char *PackedFile, char *SubPath, char *SrcPath, char *AddList, int Flag
}
}
fclose(handle_to_add);
ret = DFS_OpenFile(&archive_handle.vi[partition], (uint8_t *)current_short_filename, DFS_WRITE, scratch_sector, &fi, file_timestamp);
ret = DFS_OpenFile(&archive_handle.vi[partition], (uint8_t *)current_short_filename, DFS_WRITE | DFS_DELETEOPEN, scratch_sector, &fi, file_timestamp);
if (ret != DFS_OK)
{
free(read_buf);
Expand Down
10 changes: 10 additions & 0 deletions dosfs-1.03/dosfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,16 @@ uint32_t DFS_OpenFile(PVOLINFO volinfo, uint8_t *path, uint8_t mode, uint8_t *sc
//return DFS_NOTFOUND;
return DFS_ISDIRECTORY;

// ggn: If we opened the file for writing and it exists, delete it
// (TODO: this is optional, perhaps it should be the default, so we match all fopen() implementations)
if (mode & DFS_DELETEOPEN && mode & DFS_WRITE)
{
if (DFS_UnlinkFile(volinfo, path, scratch))
return DFS_ERRMISC;
// Fallthrough to the new file code below
break;
}

return DFS_OK;
}
}
Expand Down
3 changes: 2 additions & 1 deletion dosfs-1.03/dosfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ uint32_t DFS_WriteSector(uint8_t unit, uint8_t *buffer, uint32_t sector, uint32_
// File access modes
#define DFS_READ 1 // read-only
#define DFS_WRITE 2 // write-only
#define DFS_FOLDER 4 // create folder (ggn)
#define DFS_FOLDER 4 // (ggn) create folder
#define DFS_DELETEOPEN 8 // (ggn) when opening file for write, delete it if it exists

//===================================================================
// Miscellaneous constants
Expand Down
Binary file modified install/jacknife.wcx
Binary file not shown.
Binary file modified install/jacknife.wcx64
Binary file not shown.
Binary file modified install/jacknife.zip
Binary file not shown.
Binary file modified install/jacknife_ctrlpagedownonly.zip
Binary file not shown.
9 changes: 4 additions & 5 deletions install/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Progress bar info during operations |✓|✓ |&c

### What's missing, but planned (in order of severity/implementation likelihood)

- When adding files, check if file already exists and delete it
- Extended (XGM) partition support
- `.ini` file with various settings (specify if creating a HD disk image is allowed, customisable hard disk image extension, etc)
- Writing .DIM images (only opening and extracting is possible at the moment)
Expand Down Expand Up @@ -78,10 +77,10 @@ Again, this program requires a manual installation:
## Credits
- FAT12/16/32 reader "PetitFAT" used in older versions taken from here: http://www.elm-chan.org/fsw/ff/00index_p.html (slightly modified)
- DOSFS library obtained from http://www.larwe.com/zws/products/dosfs/index.html (appears to be Public Domain licensed), modified and debugged (especially for FAT12)
- Original plugin code by @tin-nl
- Extended and replaced FAT library by @ggnkua
- Linux/Mac fix by @tattlemuss
- Uses *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / pcg-random.org. Licensed under Apache License 2.0 (NO WARRANTY, etc. see website)
- Original plugin code by <a href=https://github.com/tin-nl>@tin-nl</a>
- Extended and replaced FAT library by <a href=https://github.com/ggnkua>@ggnkua</a>
- Linux/Mac fix by <a href=https://github.com/tattlemuss>@tattlemuss</a>
- Uses *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / <a href=https://www.pcg-random.org>pcg-random.org</a>. Licensed under Apache License 2.0 (NO WARRANTY, etc. see website)
- Some code borrowed from [SdFat libary](https://github.com/greiman/SdFat), which carries the following license:
`MIT License

Expand Down
9 changes: 4 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Progress bar info during operations |&check;|&check; |&c

### What's missing, but planned (in order of severity/implementation likelihood)

- When adding files, check if file already exists and delete it
- Extended (XGM) partition support
- `.ini` file with various settings (specify if creating a HD disk image is allowed, customisable hard disk image extension, etc)
- Writing .DIM images (only opening and extracting is possible at the moment)
Expand Down Expand Up @@ -78,10 +77,10 @@ Again, this program requires a manual installation:
## Credits
- FAT12/16/32 reader "PetitFAT" used in older versions taken from here: http://www.elm-chan.org/fsw/ff/00index_p.html (slightly modified)
- DOSFS library obtained from http://www.larwe.com/zws/products/dosfs/index.html (appears to be Public Domain licensed), modified and debugged (especially for FAT12)
- Original plugin code by @tin-nl
- Extended and replaced FAT library by @ggnkua
- Linux/Mac fix by @tattlemuss
- Uses *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / pcg-random.org. Licensed under Apache License 2.0 (NO WARRANTY, etc. see website)
- Original plugin code by <a href=https://github.com/tin-nl>@tin-nl</a>
- Extended and replaced FAT library by <a href=https://github.com/ggnkua>@ggnkua</a>
- Linux/Mac fix by <a href=https://github.com/tattlemuss>@tattlemuss</a>
- Uses *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / <a href=https://www.pcg-random.org>pcg-random.org</a>. Licensed under Apache License 2.0 (NO WARRANTY, etc. see website)
- Some code borrowed from [SdFat libary](https://github.com/greiman/SdFat), which carries the following license:
`MIT License

Expand Down

0 comments on commit c1be29d

Please sign in to comment.