Skip to content

Commit a98b184

Browse files
committedFeb 2, 2024
Hack to avoid a case where CH QC could corrupt files
1 parent ccc2fbf commit a98b184

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed
 

‎haskell/packages/onyx-exe-toolkit/src/Onyx/GUI.hs

+20-14
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,7 @@ pageQuickConvertCH sink rect tab startTasks = mdo
22112211
(trimClock 5 10 5 10 -> row2, row34) = chopBottom 84 bottomRect
22122212
[row3, row4] = map (trimClock 5 10 5 10) $ splitVertN 2 row34
22132213
updateFiles = modifyMVar_ loadedFiles
2214-
filesGroup <- fileLoadWindow filesRect sink "CH song" "CH songs" updateFiles [] searchQuickFoF
2214+
(filesGroup, clearFiles) <- fileLoadWindow' filesRect sink "CH song" "CH songs" updateFiles [] searchQuickFoF
22152215
$ \qfof -> let
22162216
entry = T.pack $ qfof.location
22172217
subline = case qfof.format of
@@ -2301,15 +2301,19 @@ pageQuickConvertCH sink rect tab startTasks = mdo
23012301
transform <- getTransform
23022302
let warningText = "This will modify the selected songs, and the old versions will be deleted."
23032303
FL.flChoice warningText "Cancel" (Just "Start") Nothing >>= \case
2304-
1 -> sink $ EventOnyx $ startTasks $ flip map qfofs $ \orig -> let
2305-
loc = orig.location
2306-
task = do
2307-
qfof <- transform orig
2308-
stackIO $ case qfof.format of
2309-
FoFFolder -> saveQuickFoFFolder loc qfof
2310-
FoFSNG -> saveQuickFoFSNG loc qfof
2311-
return [loc]
2312-
in (loc, task)
2304+
1 -> sink $ EventOnyx $ do
2305+
-- TODO this is a hack to avoid stale .sng references after editing them.
2306+
-- should come up with a better solution!
2307+
stackIO clearFiles
2308+
startTasks $ flip map qfofs $ \orig -> let
2309+
loc = orig.location
2310+
task = do
2311+
qfof <- transform orig
2312+
stackIO $ case qfof.format of
2313+
FoFFolder -> saveQuickFoFFolder loc qfof
2314+
FoFSNG -> saveQuickFoFSNG loc qfof
2315+
return [loc]
2316+
in (loc, task)
23132317
_ -> return ()
23142318

23152319
let computeTasks qfofs ext template deleteOriginals = forM qfofs $ \qfof -> do
@@ -2348,8 +2352,9 @@ pageQuickConvertCH sink rect tab startTasks = mdo
23482352
qfofs <- readMVar loadedFiles
23492353
transform <- getTransform
23502354
tasks <- computeTasks qfofs "" template deleteOriginals
2351-
promptTasks tasks $ do
2352-
sink $ EventOnyx $ startTasks $ flip map tasks $ \(orig, _, taskType, fout) -> let
2355+
promptTasks tasks $ sink $ EventOnyx $ do
2356+
stackIO clearFiles -- hack as mentioned above
2357+
startTasks $ flip map tasks $ \(orig, _, taskType, fout) -> let
23532358
task = do
23542359
qfof <- transform orig
23552360
stackIO $ saveQuickFoFFolder fout qfof
@@ -2372,8 +2377,9 @@ pageQuickConvertCH sink rect tab startTasks = mdo
23722377
qfofs <- readMVar loadedFiles
23732378
transform <- getTransform
23742379
tasks <- computeTasks qfofs "sng" template deleteOriginals
2375-
promptTasks tasks $ do
2376-
sink $ EventOnyx $ startTasks $ flip map tasks $ \(orig, _, taskType, fout) -> let
2380+
promptTasks tasks $ sink $ EventOnyx $ do
2381+
stackIO clearFiles -- hack as mentioned above
2382+
startTasks $ flip map tasks $ \(orig, _, taskType, fout) -> let
23772383
task = do
23782384
qfof <- transform orig
23792385
stackIO $ saveQuickFoFSNG fout qfof

‎haskell/packages/onyx-exe-toolkit/src/Onyx/GUI/Core.hs

+16-2
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,21 @@ fileLoadWindow
571571
-> (FilePath -> Onyx ([FilePath], [a])) -- ^ one step of file search process
572572
-> (a -> (T.Text, [T.Text])) -- ^ display an entry in the tree
573573
-> IO (FL.Ref FL.Group)
574-
fileLoadWindow rect sink single plural modifyFiles startFiles step display = mdo
574+
fileLoadWindow rect sink single plural modifyFiles startFiles step display
575+
= fmap fst
576+
$ fileLoadWindow' rect sink single plural modifyFiles startFiles step display
577+
578+
fileLoadWindow'
579+
:: Rectangle
580+
-> (Event -> IO ())
581+
-> T.Text -- ^ singular
582+
-> T.Text -- ^ plural
583+
-> (([a] -> IO [a]) -> IO ()) -- ^ read and/or modify the current list of files
584+
-> [FilePath] -- ^ initial paths to start searching
585+
-> (FilePath -> Onyx ([FilePath], [a])) -- ^ one step of file search process
586+
-> (a -> (T.Text, [T.Text])) -- ^ display an entry in the tree
587+
-> IO (FL.Ref FL.Group, IO ())
588+
fileLoadWindow' rect sink single plural modifyFiles startFiles step display = mdo
575589
group <- FL.groupNew rect Nothing
576590
let (labelRect, belowLabel) = chopTop 40 rect
577591
(termRect, buttonsRect) = chopBottom 50 belowLabel
@@ -682,7 +696,7 @@ fileLoadWindow rect sink single plural modifyFiles startFiles step display = mdo
682696
btnB <- FL.buttonNew btnRectB' $ Just $ "Clear " <> plural
683697
FL.setCallback btnB $ \_ -> sink $ EventIO clearFiles
684698
FL.end group
685-
return group
699+
return (group, clearFiles)
686700

687701
dragAndDrop
688702
:: ([String] -> IO ())

0 commit comments

Comments
 (0)
Please sign in to comment.