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
b38ea101
Commit
b38ea101
authored
Apr 04, 2019
by
feihuaduo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增读取额外卡库压缩包数据库卡图
parent
f94ac2ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
2 deletions
+103
-2
mobile/src/main/java/cn/garymb/ygomobile/loader/ImageLoader.java
...src/main/java/cn/garymb/ygomobile/loader/ImageLoader.java
+47
-0
mobile/src/main/java/ocgcore/CardManager.java
mobile/src/main/java/ocgcore/CardManager.java
+56
-2
No files found.
mobile/src/main/java/cn/garymb/ygomobile/loader/ImageLoader.java
View file @
b38ea101
...
@@ -23,6 +23,8 @@ import java.io.Closeable;
...
@@ -23,6 +23,8 @@ import java.io.Closeable;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipEntry
;
...
@@ -43,6 +45,7 @@ import static com.bumptech.glide.Glide.with;
...
@@ -43,6 +45,7 @@ import static com.bumptech.glide.Glide.with;
public
class
ImageLoader
implements
Closeable
{
public
class
ImageLoader
implements
Closeable
{
private
static
final
String
TAG
=
ImageLoader
.
class
.
getSimpleName
();
private
static
final
String
TAG
=
ImageLoader
.
class
.
getSimpleName
();
private
ZipFile
mZipFile
;
private
ZipFile
mZipFile
;
private
List
<
ZipFile
>
zipFileList
;
private
LruBitmapPool
mLruBitmapPool
;
private
LruBitmapPool
mLruBitmapPool
;
// private ExecutorService mExecutorService = Executors.newSingleThreadExecutor();
// private ExecutorService mExecutorService = Executors.newSingleThreadExecutor();
private
boolean
isClose
=
false
;
private
boolean
isClose
=
false
;
...
@@ -72,6 +75,7 @@ public class ImageLoader implements Closeable {
...
@@ -72,6 +75,7 @@ public class ImageLoader implements Closeable {
private
ImageLoader
(
Context
context
)
{
private
ImageLoader
(
Context
context
)
{
mContext
=
context
;
mContext
=
context
;
mLruBitmapPool
=
new
LruBitmapPool
(
100
);
mLruBitmapPool
=
new
LruBitmapPool
(
100
);
zipFileList
=
new
ArrayList
<>();
}
}
private
class
BpgResourceDecoder
implements
ResourceDecoder
<
ImageVideoWrapper
,
GifBitmapWrapper
>
{
private
class
BpgResourceDecoder
implements
ResourceDecoder
<
ImageVideoWrapper
,
GifBitmapWrapper
>
{
...
@@ -179,6 +183,7 @@ public class ImageLoader implements Closeable {
...
@@ -179,6 +183,7 @@ public class ImageLoader implements Closeable {
String
path
=
AppsSettings
.
get
().
getResourcePath
();
String
path
=
AppsSettings
.
get
().
getResourcePath
();
boolean
bind
=
false
;
boolean
bind
=
false
;
File
zip
=
new
File
(
path
,
Constants
.
CORE_PICS_ZIP
);
File
zip
=
new
File
(
path
,
Constants
.
CORE_PICS_ZIP
);
List
<
File
>
zipList
=
new
ArrayList
<>();
for
(
String
ex
:
Constants
.
IMAGE_EX
)
{
for
(
String
ex
:
Constants
.
IMAGE_EX
)
{
File
file
=
new
File
(
AppsSettings
.
get
().
getResourcePath
(),
name
+
ex
);
File
file
=
new
File
(
AppsSettings
.
get
().
getResourcePath
(),
name
+
ex
);
File
file_ex
=
new
File
(
AppsSettings
.
get
().
getResourcePath
(),
name_ex
+
ex
);
File
file_ex
=
new
File
(
AppsSettings
.
get
().
getResourcePath
(),
name_ex
+
ex
);
...
@@ -218,6 +223,48 @@ public class ImageLoader implements Closeable {
...
@@ -218,6 +223,48 @@ public class ImageLoader implements Closeable {
IOUtils
.
close
(
inputStream
);
IOUtils
.
close
(
inputStream
);
}
}
}
}
if
(!
bind
)
{
File
[]
files
=
new
File
(
AppsSettings
.
get
().
getResourcePath
(),
Constants
.
CORE_EXPANSIONS
).
listFiles
();
if
(
files
!=
null
)
{
for
(
File
file
:
files
)
{
if
(
file
.
isFile
()
&&
file
.
getName
().
endsWith
(
".zip"
))
{
ZipEntry
entry
=
null
;
InputStream
inputStream
=
null
;
ByteArrayOutputStream
outputStream
=
null
;
try
{
ZipFile
zipFile
=
null
;
for
(
ZipFile
zipFile1:
zipFileList
){
if
(
zipFile1
.
getName
().
equals
(
file
.
getAbsolutePath
())){
zipFile
=
zipFile1
;
break
;
}
}
if
(
zipFile
==
null
){
zipFile
=
new
ZipFile
(
file
.
getAbsoluteFile
());
zipFileList
.
add
(
zipFile
);
}
for
(
String
ex
:
Constants
.
IMAGE_EX
)
{
entry
=
zipFile
.
getEntry
(
name
+
ex
);
if
(
entry
!=
null
)
{
inputStream
=
zipFile
.
getInputStream
(
entry
);
outputStream
=
new
ByteArrayOutputStream
();
IOUtils
.
copy
(
inputStream
,
outputStream
);
bind
(
outputStream
.
toByteArray
(),
imageview
,
Constants
.
BPG
.
equals
(
ex
),
code
,
pre
,
isBig
);
bind
=
true
;
break
;
}
}
if
(
bind
)
break
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
IOUtils
.
close
(
inputStream
);
}
}
}
}
}
if
(!
bind
)
{
if
(!
bind
)
{
if
(
Constants
.
NETWORK_IMAGE
&&
NetUtils
.
isWifiConnected
(
imageview
.
getContext
()))
{
if
(
Constants
.
NETWORK_IMAGE
&&
NetUtils
.
isWifiConnected
(
imageview
.
getContext
()))
{
bind
(
String
.
format
(
Constants
.
IMAGE_URL
,
""
+
code
),
imageview
,
code
,
pre
,
isBig
);
bind
(
String
.
format
(
Constants
.
IMAGE_URL
,
""
+
code
),
imageview
,
code
,
pre
,
isBig
);
...
...
mobile/src/main/java/ocgcore/CardManager.java
View file @
b38ea101
...
@@ -6,9 +6,21 @@ import android.support.annotation.WorkerThread;
...
@@ -6,9 +6,21 @@ import android.support.annotation.WorkerThread;
import
android.util.Log
;
import
android.util.Log
;
import
android.util.SparseArray
;
import
android.util.SparseArray
;
import
java.io.BufferedInputStream
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.FilenameFilter
;
import
java.io.FilenameFilter
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipFile
;
import
java.util.zip.ZipInputStream
;
import
cn.garymb.ygomobile.App
;
import
cn.garymb.ygomobile.AppsSettings
;
import
cn.garymb.ygomobile.AppsSettings
;
import
cn.garymb.ygomobile.utils.IOUtils
;
import
cn.garymb.ygomobile.utils.IOUtils
;
import
ocgcore.data.Card
;
import
ocgcore.data.Card
;
...
@@ -47,13 +59,24 @@ public class CardManager {
...
@@ -47,13 +59,24 @@ public class CardManager {
@Override
@Override
public
boolean
accept
(
File
dir
,
String
name
)
{
public
boolean
accept
(
File
dir
,
String
name
)
{
File
file
=
new
File
(
dir
,
name
);
File
file
=
new
File
(
dir
,
name
);
return
file
.
isFile
()
&&
name
.
endsWith
(
".cdb"
);
return
file
.
isFile
()
&&
(
name
.
endsWith
(
".cdb"
)||
name
.
endsWith
(
".zip"
)
);
}
}
});
});
//读取全部卡片
//读取全部卡片
if
(
files
!=
null
)
{
if
(
files
!=
null
)
{
for
(
File
file
:
files
)
{
for
(
File
file
:
files
)
{
count
=
readAllCards
(
file
,
cardDataHashMap
);
if
(
file
.
getName
().
endsWith
(
".cdb"
)){
count
=
readAllCards
(
file
,
cardDataHashMap
);
}
else
if
(
file
.
getName
().
endsWith
(
".zip"
)){
Log
.
e
(
"CardManager"
,
"读取压缩包"
);
try
{
for
(
File
file1:
readZipCdb
(
file
.
getAbsolutePath
())){
count
=
readAllCards
(
file1
,
cardDataHashMap
);
}
}
catch
(
IOException
e
)
{
Log
.
e
(
"CardManager"
,
"读取压缩包错误"
+
e
);
}
}
Log
.
i
(
"Irrlicht"
,
"load "
+
count
+
" cdb:"
+
file
);
Log
.
i
(
"Irrlicht"
,
"load "
+
count
+
" cdb:"
+
file
);
}
}
}
}
...
@@ -96,6 +119,37 @@ public class CardManager {
...
@@ -96,6 +119,37 @@ public class CardManager {
return
rs
;
return
rs
;
}
}
public
static
List
<
File
>
readZipCdb
(
String
zipPath
)
throws
IOException
{
String
savePath
=
App
.
get
().
getExternalCacheDir
().
getAbsolutePath
();
List
<
File
>
fileList
=
new
ArrayList
<>();
int
num
=
0
;
ZipFile
zf
=
new
ZipFile
(
zipPath
);
InputStream
in
=
new
BufferedInputStream
(
new
FileInputStream
(
zipPath
));
ZipInputStream
zin
=
new
ZipInputStream
(
in
);
ZipEntry
ze
;
while
((
ze
=
zin
.
getNextEntry
())
!=
null
)
{
if
(
ze
.
isDirectory
())
{
//Do nothing
}
else
{
if
(
ze
.
getName
().
endsWith
(
".cdb"
))
{
File
file
=
new
File
(
savePath
,
"cards"
+
num
+
".cdb"
);
InputStream
inputStream
=
zf
.
getInputStream
(
ze
);
OutputStream
os
=
new
FileOutputStream
(
file
);
int
bytesRead
=
0
;
byte
[]
buffer
=
new
byte
[
8192
];
while
((
bytesRead
=
inputStream
.
read
(
buffer
,
0
,
8192
))
!=
-
1
)
{
os
.
write
(
buffer
,
0
,
bytesRead
);
}
os
.
close
();
inputStream
.
close
();
fileList
.
add
(
file
);
}
}
}
zin
.
closeEntry
();
return
fileList
;
}
@WorkerThread
@WorkerThread
protected
int
readAllCards
(
File
file
,
SparseArray
<
Card
>
cardMap
)
{
protected
int
readAllCards
(
File
file
,
SparseArray
<
Card
>
cardMap
)
{
if
(!
file
.
exists
())
{
if
(!
file
.
exists
())
{
...
...
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