This commit is contained in:
Liang Ding 2022-12-23 16:19:36 +08:00
parent 2b451eddad
commit 7ef54b0f8f
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 37 additions and 1 deletions

View file

@ -293,6 +293,8 @@ func InitFlashcards() {
return
}
Decks = map[string]*riff.Deck{}
entries, err := os.ReadDir(riffSavePath)
if nil != err {
logging.LogErrorf("read riff dir failed: %s", err)
@ -320,7 +322,7 @@ func InitFlashcards() {
}
}
func RenameDeck(deckID string, name string) (err error) {
func RenameDeck(deckID, name string) (err error) {
deckLock.Lock()
deck := Decks[deckID]
deckLock.Unlock()
@ -334,6 +336,21 @@ func RenameDeck(deckID string, name string) (err error) {
return
}
func RemoveDeck(deckID string) (err error) {
riffSavePath := getRiffDir()
deckPath := filepath.Join(riffSavePath, deckID+".deck")
if err = os.Remove(deckPath); nil != err {
return
}
cardsPath := filepath.Join(riffSavePath, deckID+".cards")
if err = os.Remove(cardsPath); nil != err {
return
}
InitFlashcards()
return
}
func CreateDeck(name string) (deck *riff.Deck, err error) {
riffSavePath := getRiffDir()
deckID := ast.NewNodeID()