@@ -204,7 +204,8 @@ public void onSuccess(String downloadUrl) {
204204 body .setVisibility (View .VISIBLE );
205205 dialog .dismiss ();
206206 showTip (R .string .download_archive_started , LENGTH_SHORT );
207- String fileName = galleryDetail .title .replaceAll ("/" ,"" );
207+ // String fileName = galleryDetail.title.replaceAll("/","");
208+ String fileName = createFileName (galleryDetail .title );
208209 Uri downloadUri = Uri .parse (downloadUrl );
209210 DownloadManager .Request request = new DownloadManager .Request (downloadUri );
210211 request .setAllowedNetworkTypes (DownloadManager .Request .NETWORK_MOBILE | DownloadManager .Request .NETWORK_WIFI );
@@ -313,7 +314,8 @@ private void unzipAndImportFile(Cursor cursor) throws IllegalArgumentException,
313314 return ;
314315 }
315316 long downloadId = cursor .getLong (cursor .getColumnIndexOrThrow (DownloadManager .COLUMN_ID ));
316- String fileName = galleryDetail .title .replaceAll ("/" ,"" );
317+ // String fileName = galleryDetail.title.replaceAll("/","");
318+ String fileName = createFileName (galleryDetail .title );
317319 String tempFilePath = tempDir .getPath () + "/" + fileName ;
318320 String zipFilePath = zipFile .getPath ();
319321 new Thread (() -> {
@@ -399,4 +401,24 @@ private void importGallery(String tempFilePath, long downloadId) {
399401 });
400402 }
401403 }
404+
405+ /**
406+ * 去除输入字符串中的'\'、'/'、'|'字符
407+ * 创建文件名的静态私有方法
408+ * @param name 原始名称参数
409+ * @return 返回处理后的文件名字符串
410+ */
411+ static private String createFileName (String name ){
412+ if (name == null ) {
413+ throw new IllegalArgumentException ("Input name cannot be null" );
414+ }
415+ if (name .isEmpty ()) {
416+ return "" ;
417+ }
418+ String result = name .replaceAll ("/" ,"" );
419+ result = result .replaceAll ("\\ |" ,"" );
420+ return result ;
421+ // 使用正则表达式替换非法字符
422+ // return name.replaceAll("[\\\\/|]", "");
423+ }
402424}
0 commit comments