mirror of
https://github.com/jiojciojsioe3/a3cjroijsiojiorj.git
synced 2024-11-15 15:31:51 +08:00
Support restoring multiple folders imported by dragging
This commit is contained in:
parent
9c44d223c4
commit
657c631769
@ -151,7 +151,7 @@ class CustomSongs{
|
|||||||
if(typeof showDirectoryPicker === "function"){
|
if(typeof showDirectoryPicker === "function"){
|
||||||
return showDirectoryPicker().then(file => {
|
return showDirectoryPicker().then(file => {
|
||||||
this.walkFilesystem(file).then(files => this.importLocal(files)).then(e => {
|
this.walkFilesystem(file).then(files => this.importLocal(files)).then(e => {
|
||||||
db.setItem("customFolder", file)
|
db.setItem("customFolder", [file])
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
if(e !== "cancel"){
|
if(e !== "cancel"){
|
||||||
return Promise.reject(e)
|
return Promise.reject(e)
|
||||||
@ -169,23 +169,22 @@ class CustomSongs{
|
|||||||
}
|
}
|
||||||
this.importLocal(files)
|
this.importLocal(files)
|
||||||
}
|
}
|
||||||
walkFilesystem(dir, path=dir.name + "/", output=[]){
|
walkFilesystem(file, path="", output=[]){
|
||||||
return filePermission(dir).then(dir => {
|
if(file.kind === "directory"){
|
||||||
var values = dir.values()
|
return filePermission(file).then(file => {
|
||||||
|
var values = file.values()
|
||||||
var walkValues = () => values.next().then(generator => {
|
var walkValues = () => values.next().then(generator => {
|
||||||
if(generator.done){
|
if(generator.done){
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
var file = generator.value
|
return this.walkFilesystem(generator.value, path + file.name + "/", output).then(() => walkValues())
|
||||||
if(file.kind === "directory"){
|
|
||||||
return this.walkFilesystem(file, path + file.name + "/", output).then(() => walkValues())
|
|
||||||
}else{
|
|
||||||
output.push(new FilesystemFile(file, path + file.name))
|
|
||||||
return walkValues()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
return walkValues()
|
return walkValues()
|
||||||
}, () => Promise.resolve())
|
}, () => Promise.resolve())
|
||||||
|
}else{
|
||||||
|
output.push(new FilesystemFile(file, path + file.name))
|
||||||
|
return Promise.resolve(output)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
filesDropped(event){
|
filesDropped(event){
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
@ -196,22 +195,14 @@ class CustomSongs{
|
|||||||
}
|
}
|
||||||
var allFiles = []
|
var allFiles = []
|
||||||
var dropPromises = []
|
var dropPromises = []
|
||||||
var dropLength = event.dataTransfer.items.length
|
var dbItems = []
|
||||||
for(var i = 0; i < dropLength; i++){
|
for(var i = 0; i < event.dataTransfer.items.length; i++){
|
||||||
var item = event.dataTransfer.items[i]
|
var item = event.dataTransfer.items[i]
|
||||||
let promise
|
let promise
|
||||||
if(item.getAsFileSystemHandle){
|
if(item.getAsFileSystemHandle){
|
||||||
promise = item.getAsFileSystemHandle().then(file => {
|
promise = item.getAsFileSystemHandle().then(file => {
|
||||||
if(file.kind === "directory"){
|
dbItems.push(file)
|
||||||
return this.walkFilesystem(file).then(files => {
|
return this.walkFilesystem(file)
|
||||||
if(files.length && dropLength === 1){
|
|
||||||
db.setItem("customFolder", file)
|
|
||||||
}
|
|
||||||
return files
|
|
||||||
})
|
|
||||||
}else{
|
|
||||||
return [new FilesystemFile(file, file.name)]
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
var entry = item.webkitGetAsEntry()
|
var entry = item.webkitGetAsEntry()
|
||||||
@ -225,7 +216,11 @@ class CustomSongs{
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Promise.all(dropPromises).then(() => this.importLocal(allFiles))
|
Promise.all(dropPromises).then(() => this.importLocal(allFiles)).then(() => {
|
||||||
|
if(dbItems.length){
|
||||||
|
db.setItem("customFolder", dbItems)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
walkEntry(entry, path="", output=[]){
|
walkEntry(entry, path="", output=[]){
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
@ -74,10 +74,15 @@ class Titlescreen{
|
|||||||
if(this.customFolder && !fromP2 && !assets.customSongs){
|
if(this.customFolder && !fromP2 && !assets.customSongs){
|
||||||
var customSongs = new CustomSongs(this.touched, true)
|
var customSongs = new CustomSongs(this.touched, true)
|
||||||
var soundPlayed = false
|
var soundPlayed = false
|
||||||
customSongs.walkFilesystem(this.customFolder).then(files => {
|
var promises = []
|
||||||
|
var allFiles = []
|
||||||
|
this.customFolder.forEach(file => {
|
||||||
|
promises.push(customSongs.walkFilesystem(file, undefined, allFiles))
|
||||||
|
})
|
||||||
|
Promise.all(promises).then(() => {
|
||||||
assets.sounds["se_don"].play()
|
assets.sounds["se_don"].play()
|
||||||
soundPlayed = true
|
soundPlayed = true
|
||||||
return customSongs.importLocal(files)
|
return customSongs.importLocal(allFiles)
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
localStorage.removeItem("customSelected")
|
localStorage.removeItem("customSelected")
|
||||||
db.removeItem("customFolder")
|
db.removeItem("customFolder")
|
||||||
|
Loading…
Reference in New Issue
Block a user