Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
YGOMobile
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fallenstardust
YGOMobile
Commits
15d827a3
Commit
15d827a3
authored
Sep 24, 2021
by
qq247321453
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IOUtils
parent
c919fe4e
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
45 additions
and
60 deletions
+45
-60
mobile/src/main/java/cn/garymb/ygomobile/GameUriManager.java
mobile/src/main/java/cn/garymb/ygomobile/GameUriManager.java
+2
-7
mobile/src/main/java/cn/garymb/ygomobile/ui/file/FileActivity.java
...c/main/java/cn/garymb/ygomobile/ui/file/FileActivity.java
+3
-1
mobile/src/main/java/cn/garymb/ygomobile/ui/home/ImageUpdater.java
...c/main/java/cn/garymb/ygomobile/ui/home/ImageUpdater.java
+2
-4
mobile/src/main/java/cn/garymb/ygomobile/ui/home/ResCheckTask.java
...c/main/java/cn/garymb/ygomobile/ui/home/ResCheckTask.java
+1
-3
mobile/src/main/java/cn/garymb/ygomobile/ui/preference/PreferenceFragmentPlus.java
...arymb/ygomobile/ui/preference/PreferenceFragmentPlus.java
+1
-1
mobile/src/main/java/cn/garymb/ygomobile/ui/preference/fragments/SettingFragment.java
...mb/ygomobile/ui/preference/fragments/SettingFragment.java
+5
-5
mobile/src/main/java/cn/garymb/ygomobile/utils/FileUtils.java
...le/src/main/java/cn/garymb/ygomobile/utils/FileUtils.java
+19
-31
mobile/src/main/java/cn/garymb/ygomobile/utils/IOUtils.java
mobile/src/main/java/cn/garymb/ygomobile/utils/IOUtils.java
+8
-6
mobile/src/main/java/cn/garymb/ygomobile/utils/YGODialogUtil.java
...rc/main/java/cn/garymb/ygomobile/utils/YGODialogUtil.java
+4
-2
No files found.
mobile/src/main/java/cn/garymb/ygomobile/GameUriManager.java
View file @
15d827a3
...
...
@@ -114,9 +114,7 @@ public class GameUriManager {
}
return
new
File
(
dir
,
"tmp_"
+
System
.
currentTimeMillis
()
+
".ydk"
);
}
else
{
if
(!
dir
.
exists
())
{
dir
.
mkdirs
();
}
IOUtils
.
createFolder
(
dir
);
}
return
file
;
}
...
...
@@ -180,10 +178,7 @@ public class GameUriManager {
ParcelFileDescriptor
pfd
=
null
;
FileInputStream
input
=
null
;
try
{
File
dir
=
local
.
getParentFile
();
if
(!
dir
.
exists
())
{
dir
.
mkdirs
();
}
IOUtils
.
createFolder
(
local
.
getParentFile
());
if
(
remoteFile
!=
null
)
{
FileUtils
.
copyFile
(
remoteFile
,
local
);
}
else
{
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/file/FileActivity.java
View file @
15d827a3
...
...
@@ -21,6 +21,8 @@ import java.io.File;
import
cn.garymb.ygomobile.lite.R
;
import
cn.garymb.ygomobile.ui.activities.BaseActivity
;
import
cn.garymb.ygomobile.utils.FileUtils
;
import
cn.garymb.ygomobile.utils.IOUtils
;
public
class
FileActivity
extends
BaseActivity
implements
AdapterView
.
OnItemClickListener
,
AdapterView
.
OnItemLongClickListener
...
...
@@ -82,7 +84,7 @@ public class FileActivity extends BaseActivity implements AdapterView.OnItemClic
return
;
}
File
dir
=
new
File
(
mFileAdapter
.
getCurPath
(),
name
);
dir
.
mkdirs
(
);
IOUtils
.
createFolder
(
dir
);
if
(
dir
.
isDirectory
())
{
mFileAdapter
.
setPath
(
dir
.
getAbsolutePath
());
}
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/home/ImageUpdater.java
View file @
15d827a3
...
...
@@ -24,6 +24,7 @@ import cn.garymb.ygomobile.lite.R;
import
cn.garymb.ygomobile.ui.activities.BaseActivity
;
import
cn.garymb.ygomobile.ui.plus.DialogPlus
;
import
cn.garymb.ygomobile.ui.plus.VUiKit
;
import
cn.garymb.ygomobile.utils.FileUtils
;
import
cn.garymb.ygomobile.utils.IOUtils
;
import
ocgcore.DataManager
;
import
ocgcore.data.Card
;
...
...
@@ -261,10 +262,7 @@ public class ImageUpdater implements DialogInterface.OnCancelListener {
if
(
file
.
exists
())
{
file
.
delete
();
}
else
{
File
dir
=
file
.
getParentFile
();
if
(!
dir
.
exists
())
{
dir
.
mkdirs
();
}
IOUtils
.
createFolder
(
file
.
getParentFile
());
}
file
.
createNewFile
();
mConnection
=
(
HttpURLConnection
)
new
URL
(
url
).
openConnection
();
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/home/ResCheckTask.java
View file @
15d827a3
...
...
@@ -324,9 +324,7 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
File
dirFile
=
null
;
for
(
String
dir
:
dirs
)
{
dirFile
=
new
File
(
mSettings
.
getResourcePath
(),
dir
);
if
(!
dirFile
.
exists
())
{
dirFile
.
mkdirs
();
}
IOUtils
.
createFolder
(
dirFile
);
}
}
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/preference/PreferenceFragmentPlus.java
View file @
15d827a3
...
...
@@ -176,7 +176,7 @@ public abstract class PreferenceFragmentPlus extends BasePreferenceFragment {
if
(
mCurImageInfo
!=
null
)
{
String
cachePath
=
photos
.
get
(
0
);
try
{
FileUtils
.
copyFile
(
cachePath
,
mCurImageInfo
.
mOutFile
,
true
);
FileUtils
.
copyFile
(
cachePath
,
mCurImageInfo
.
mOutFile
);
}
catch
(
IOException
e
)
{
Toast
.
makeText
(
getContext
(),
e
+
""
,
Toast
.
LENGTH_LONG
).
show
();
onChooseFileFail
(
curPreference
);
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/preference/fragments/SettingFragment.java
View file @
15d827a3
...
...
@@ -437,7 +437,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
process
.
waitFor
();
IOUtils
.
delete
(
soFile
);
FileUtils
.
copyFile
(
file
,
soFile
.
getAbsolutePath
()
,
true
);
FileUtils
.
copyFile
(
file
,
soFile
.
getAbsolutePath
());
me
.
what
=
COPY_SO_OK
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
@@ -546,22 +546,22 @@ public class SettingFragment extends PreferenceFragmentPlus {
private
void
setPendlumScale
(
boolean
ok
)
{
if
(
Constants
.
DEBUG
)
Log
.
i
(
"kk"
,
"setPendlumScale "
+
ok
);
File
file
=
new
File
(
mSettings
.
getResourcePath
(),
Constants
.
CORE_SKIN_PENDULUM_PATH
);
File
dir
=
new
File
(
mSettings
.
getResourcePath
(),
Constants
.
CORE_SKIN_PENDULUM_PATH
);
if
(
ok
)
{
//rename
Dialog
dlg
=
DialogPlus
.
show
(
getActivity
(),
null
,
getString
(
R
.
string
.
coping_pendulum_image
));
VUiKit
.
defer
().
when
(()
->
{
try
{
IOUtils
.
createFolder
(
file
);
IOUtils
.
createFolder
(
dir
);
IOUtils
.
copyFilesFromAssets
(
getActivity
(),
getDatapath
(
Constants
.
CORE_SKIN_PENDULUM_PATH
),
file
.
getAbsolutePath
(),
false
);
dir
.
getAbsolutePath
(),
false
);
}
catch
(
IOException
e
)
{
}
}).
done
((
re
)
->
{
dlg
.
dismiss
();
});
}
else
{
IOUtils
.
delete
(
file
);
IOUtils
.
delete
(
dir
);
}
}
...
...
mobile/src/main/java/cn/garymb/ygomobile/utils/FileUtils.java
View file @
15d827a3
...
...
@@ -5,6 +5,7 @@ import android.net.Uri;
import
android.util.Log
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.core.content.FileProvider
;
import
java.io.BufferedReader
;
...
...
@@ -101,10 +102,7 @@ public class FileUtils {
public
static
void
copyFile
(
InputStream
in
,
File
out
)
throws
IOException
{
FileOutputStream
outputStream
=
null
;
File
dir
=
out
.
getParentFile
();
if
(!
dir
.
exists
())
{
dir
.
mkdirs
();
}
IOUtils
.
createFolder
(
out
.
getParentFile
());
try
{
outputStream
=
new
FileOutputStream
(
out
);
copy
(
in
,
outputStream
);
...
...
@@ -117,10 +115,7 @@ public class FileUtils {
FileOutputStream
outputStream
=
null
;
FileInputStream
inputStream
=
null
;
try
{
File
dir
=
out
.
getParentFile
();
if
(!
dir
.
exists
())
{
dir
.
mkdirs
();
}
IOUtils
.
createFolder
(
out
.
getParentFile
());
inputStream
=
new
FileInputStream
(
in
);
outputStream
=
new
FileOutputStream
(
out
);
copy
(
inputStream
,
outputStream
);
...
...
@@ -134,7 +129,11 @@ public class FileUtils {
return
true
;
}
public
static
void
copyFile
(
String
oldPath
,
String
newPath
,
boolean
isName
)
throws
FileNotFoundException
,
IOException
{
public
static
void
copyFile
(
String
oldPath
,
String
newPath
)
throws
IOException
{
copyFile
(
oldPath
,
newPath
,
true
);
}
public
static
void
copyFile
(
String
oldPath
,
String
newPath
,
boolean
isName
)
throws
IOException
{
//判断复制后的路径是否含有文件名,如果没有则加上
if
(!
isName
)
{
...
...
@@ -155,16 +154,7 @@ public class FileUtils {
}
public
static
void
moveFile
(
String
oldPath
,
String
newPath
,
boolean
isName
)
throws
FileNotFoundException
,
IOException
{
//判断复制后的路径是否含有文件名,如果没有则加上
if
(!
isName
)
{
//由于newPath是路径加文件名,所以获取要复制的文件名与复制后的路径组成新的newPath
String
abb
[]
=
oldPath
.
split
(
"/"
);
newPath
=
newPath
+
"/"
+
abb
[
abb
.
length
-
1
];
}
public
static
void
moveFile
(
String
oldPath
,
String
newPath
)
throws
IOException
{
FileInputStream
fis
=
new
FileInputStream
(
oldPath
);
FileOutputStream
fos
=
new
FileOutputStream
(
newPath
);
byte
[]
buf
=
new
byte
[
1024
];
...
...
@@ -199,20 +189,18 @@ public class FileUtils {
if
(
filePath
==
null
)
return
;
if
(!(
new
File
(
newPath
)).
exists
())
{
(
new
File
(
newPath
)).
mkdirs
();
}
IOUtils
.
createFolder
(
new
File
(
newPath
));
for
(
int
i
=
0
;
i
<
filePath
.
length
;
i
++)
{
if
((
new
File
(
oldPath
+
file
.
separator
+
filePath
[
i
])).
isDirectory
())
{
copyDir
(
oldPath
+
file
.
separator
+
filePath
[
i
],
newPath
+
file
.
separator
+
filePath
[
i
],
false
);
}
if
(
new
File
(
oldPath
+
file
.
separator
+
filePath
[
i
]).
isFile
())
{
if
(!(
new
File
(
newPath
+
file
.
separator
+
filePath
[
i
]).
exists
())
||
isReplaced
)
copyFile
(
oldPath
+
file
.
separator
+
filePath
[
i
],
newPath
+
file
.
separator
+
filePath
[
i
],
true
);
for
(
String
path
:
filePath
)
{
File
src
=
new
File
(
oldPath
,
path
);
File
dst
=
new
File
(
newPath
,
path
);
if
(
src
.
isDirectory
())
{
copyDir
(
src
.
getPath
(),
dst
.
getPath
(),
false
);
}
else
if
(
src
.
isFile
())
{
if
(!
dst
.
exists
()
||
isReplaced
)
{
copyFile
(
src
.
getPath
(),
dst
.
getPath
());
}
}
}
}
...
...
mobile/src/main/java/cn/garymb/ygomobile/utils/IOUtils.java
View file @
15d827a3
...
...
@@ -7,6 +7,8 @@ import android.os.Build;
import
android.text.TextUtils
;
import
android.util.Log
;
import
androidx.annotation.Nullable
;
import
java.io.Closeable
;
import
java.io.File
;
import
java.io.FileOutputStream
;
...
...
@@ -160,17 +162,17 @@ public class IOUtils {
}
public
static
void
createFolderByFile
(
File
file
)
{
File
dir
=
file
.
getParentFile
();
if
(
dir
!=
null
&&
!
dir
.
exists
())
{
dir
.
mkdirs
();
}
createFolder
(
file
.
getParentFile
());
}
public
static
boolean
createFolder
(
File
file
)
{
public
static
boolean
createFolder
(
@Nullable
File
file
)
{
if
(
file
==
null
){
return
false
;
}
if
(!
file
.
exists
())
{
return
file
.
mkdirs
();
}
return
fals
e
;
return
tru
e
;
}
public
static
void
copy
(
InputStream
in
,
OutputStream
out
)
throws
IOException
{
...
...
mobile/src/main/java/cn/garymb/ygomobile/utils/YGODialogUtil.java
View file @
15d827a3
...
...
@@ -228,10 +228,11 @@ public class YGODialogUtil {
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
du
.
dis
();
DeckType
toType
=
otherType
.
get
(
position
);
IOUtils
.
createFolder
(
new
File
(
toType
.
getPath
()));
List
<
DeckFile
>
deckFileList
=
deckAdp
.
getSelectList
();
for
(
DeckFile
deckFile
:
deckFileList
)
{
try
{
FileUtils
.
moveFile
(
deckFile
.
getPath
(),
toType
.
getPath
(),
false
);
FileUtils
.
moveFile
(
deckFile
.
getPath
(),
new
File
(
toType
.
getPath
(),
deckFile
.
getName
()).
getPath
()
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
...
...
@@ -257,10 +258,11 @@ public class YGODialogUtil {
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
du
.
dis
();
DeckType
toType
=
otherType
.
get
(
position
);
IOUtils
.
createFolder
(
new
File
(
toType
.
getPath
()));
List
<
DeckFile
>
deckFileList
=
deckAdp
.
getSelectList
();
for
(
DeckFile
deckFile
:
deckFileList
)
{
try
{
FileUtils
.
copyFile
(
deckFile
.
getPath
(),
toType
.
getPath
(),
false
);
FileUtils
.
copyFile
(
deckFile
.
getPath
(),
new
File
(
toType
.
getPath
(),
deckFile
.
getName
()).
getPath
()
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment