@@ -12,7 +12,7 @@ import { GetContentRoots } from "bindings/github.com/liteldev/LeviLauncher/conte
1212import * as types from "bindings/github.com/liteldev/LeviLauncher/internal/types/models" ;
1313import { readCurrentVersionName } from "@/utils/currentVersion" ;
1414import { compareVersions } from "@/utils/version" ;
15- import { countDirectories } from "@/utils/fs" ;
15+ import { countDirectories , getPathBaseName , normalizeDroppedFiles } from "@/utils/fs" ;
1616import { getPlayerGamertagMap , listPlayers } from "@/utils/content" ;
1717import * as minecraft from "bindings/github.com/liteldev/LeviLauncher/minecraft" ;
1818import * as contentService from "bindings/github.com/liteldev/LeviLauncher/contentservice" ;
@@ -308,22 +308,23 @@ export const useContentPage = (t: TFunc) => {
308308
309309 const doImportFromPaths = async ( paths : string [ ] ) => {
310310 try {
311- if ( ! paths ?. length ) return ;
311+ const normalizedPaths = normalizeDroppedFiles ( paths ) ;
312+ if ( ! normalizedPaths . length ) return ;
312313 const name = currentVersionName || readCurrentVersionName ( ) ;
313314 if ( ! name ) {
314315 setErrorMsg ( t ( "launcherpage.currentVersion_none" ) as string ) ;
315316 return ;
316317 }
317- const hasWorld = paths . some ( ( p ) => p ?. toLowerCase ( ) . endsWith ( ".mcworld" ) ) ;
318+ const hasWorld = normalizedPaths . some ( ( p ) =>
319+ p . toLowerCase ( ) . endsWith ( ".mcworld" ) ,
320+ ) ;
318321 let hasSkin = false ;
319- if ( paths . length > 0 ) {
322+ if ( normalizedPaths . length > 0 ) {
320323 setImporting ( true ) ;
321- const firstBase =
322- paths [ 0 ] . replace ( / \\ / g, "/" ) . split ( "/" ) . pop ( ) || paths [ 0 ] ;
323- setCurrentFile ( firstBase ) ;
324+ setCurrentFile ( getPathBaseName ( normalizedPaths [ 0 ] ) ) ;
324325 }
325- for ( const p of paths ) {
326- if ( p ? .toLowerCase ( ) . endsWith ( ".mcpack" ) ) {
326+ for ( const p of normalizedPaths ) {
327+ if ( p . toLowerCase ( ) . endsWith ( ".mcpack" ) ) {
327328 const isSkin = await ( contentService as any ) ?. IsMcpackSkinPackPath ?.(
328329 p ,
329330 ) ;
@@ -338,7 +339,7 @@ export const useContentPage = (t: TFunc) => {
338339 const needsPlayer = hasWorld || ( hasSkin && ! isSharedMode ) ;
339340
340341 if ( needsPlayer ) {
341- pendingImportPathsRef . current = paths ;
342+ pendingImportPathsRef . current = normalizedPaths ;
342343 playerSelectOnOpen ( ) ;
343344 chosenPlayer = await new Promise < string > ( ( resolve ) => {
344345 playerSelectResolveRef . current = resolve ;
@@ -356,7 +357,7 @@ export const useContentPage = (t: TFunc) => {
356357 const pathsToImport =
357358 pendingImportPathsRef . current . length > 0
358359 ? pendingImportPathsRef . current
359- : paths ;
360+ : normalizedPaths ;
360361 pendingImportPathsRef . current = [ ] ;
361362 const playerToUse = chosenPlayer || selectedPlayer || "" ;
362363 for ( const p of pathsToImport ) {
@@ -366,7 +367,7 @@ export const useContentPage = (t: TFunc) => {
366367 setImporting ( true ) ;
367368 started = true ;
368369 }
369- const base = p . replace ( / \\ / g , "/" ) . split ( "/" ) . pop ( ) || p ;
370+ const base = getPathBaseName ( p ) ;
370371 setCurrentFile ( base ) ;
371372
372373 let err = "" ;
@@ -442,7 +443,7 @@ export const useContentPage = (t: TFunc) => {
442443 setImporting ( true ) ;
443444 started = true ;
444445 }
445- const base = p . replace ( / \\ / g , "/" ) . split ( "/" ) . pop ( ) || p ;
446+ const base = getPathBaseName ( p ) ;
446447 setCurrentFile ( base ) ;
447448 let err = "" ;
448449 if (
@@ -503,7 +504,7 @@ export const useContentPage = (t: TFunc) => {
503504 }
504505 succFiles . push ( base ) ;
505506 } else if ( lower . endsWith ( ".mcworld" ) ) {
506- const base = p . replace ( / \\ / g , "/" ) . split ( "/" ) . pop ( ) || p ;
507+ const base = getPathBaseName ( p ) ;
507508 if ( ! playerToUse ) {
508509 errPairs . push ( { name : base , err : "ERR_NO_PLAYER" } ) ;
509510 continue ;
@@ -683,8 +684,7 @@ export const useContentPage = (t: TFunc) => {
683684 for ( const pack of packs ) {
684685 const packPath = String ( pack ?. path || "" ) . trim ( ) ;
685686 if ( ! packPath ) continue ;
686- const fallbackName =
687- packPath . replace ( / \\ / g, "/" ) . split ( "/" ) . pop ( ) || packPath ;
687+ const fallbackName = getPathBaseName ( packPath ) ;
688688 const packName = String ( pack ?. manifest ?. name || fallbackName ) ;
689689 const itemLabel = `${ packName } -> ${ targetName } ` ;
690690 setCurrentFile ( itemLabel ) ;
@@ -774,8 +774,9 @@ export const useContentPage = (t: TFunc) => {
774774 React . useEffect ( ( ) => {
775775 return Events . On ( "files-dropped" , ( event ) => {
776776 const data = ( event . data as { files : string [ ] } ) || { } ;
777- if ( data . files && data . files . length > 0 ) {
778- void doImportRef . current ( data . files ) ;
777+ const files = normalizeDroppedFiles ( data . files ) ;
778+ if ( files . length > 0 ) {
779+ void doImportRef . current ( files ) ;
779780 }
780781 } ) ;
781782 } , [ ] ) ;
0 commit comments