Skip to content

Commit b2e5ba0

Browse files
author
Andrew Eiche
committed
Initial commit
1 parent c518004 commit b2e5ba0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+337
-0
lines changed

UnityEPubReader/Assets/Books.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

UnityEPubReader/Assets/Books/austen-pride-and-prejudice-illustrations.epub.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityEPubReader/Assets/Fonts.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
171 KB
Binary file not shown.

UnityEPubReader/Assets/Fonts/Georgia.ttf.meta

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityEPubReader/Assets/Plugins.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityEPubReader/Assets/Plugins/Android.meta

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

UnityEPubReader/Assets/Plugins/Android/zipper.jar.meta

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
452 KB
Binary file not shown.

UnityEPubReader/Assets/Plugins/Ionic.Zip.dll.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityEPubReader/Assets/Plugins/Zip.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
using System;
4+
using System.Runtime.InteropServices;
5+
using Ionic.Zip;
6+
using System.Text;
7+
using System.IO;
8+
9+
public class ZipUtil
10+
{
11+
#if UNITY_IPHONE
12+
[DllImport("__Internal")]
13+
private static extern void unzip (string zipFilePath, string location);
14+
15+
[DllImport("__Internal")]
16+
private static extern void zip (string zipFilePath);
17+
18+
[DllImport("__Internal")]
19+
private static extern void addZipFile (string addFile);
20+
21+
#endif
22+
23+
public static void Unzip (string zipFilePath, string location)
24+
{
25+
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
26+
Directory.CreateDirectory (location);
27+
28+
using (ZipFile zip = ZipFile.Read (zipFilePath)) {
29+
30+
zip.ExtractAll (location, ExtractExistingFileAction.OverwriteSilently);
31+
}
32+
#elif UNITY_ANDROID
33+
using (AndroidJavaClass zipper = new AndroidJavaClass ("com.tsw.zipper")) {
34+
zipper.CallStatic ("unzip", zipFilePath, location);
35+
}
36+
#elif UNITY_IPHONE
37+
unzip (zipFilePath, location);
38+
#endif
39+
}
40+
41+
public static void Zip (string zipFileName, params string[] files)
42+
{
43+
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
44+
string path = Path.GetDirectoryName(zipFileName);
45+
Directory.CreateDirectory (path);
46+
47+
using (ZipFile zip = new ZipFile()) {
48+
foreach (string file in files) {
49+
zip.AddFile(file, "");
50+
}
51+
zip.Save (zipFileName);
52+
}
53+
#elif UNITY_ANDROID
54+
using (AndroidJavaClass zipper = new AndroidJavaClass ("com.tsw.zipper")) {
55+
{
56+
zipper.CallStatic ("zip", zipFileName, files);
57+
}
58+
}
59+
#elif UNITY_IPHONE
60+
foreach (string file in files) {
61+
addZipFile (file);
62+
}
63+
zip (zipFileName);
64+
#endif
65+
}
66+
}

UnityEPubReader/Assets/Plugins/Zip.cs.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityEPubReader/Assets/Plugins/iOS.meta

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//
2+
// UnityZipFile.m
3+
// Unity-iPhone
4+
//
5+
// Created by 山村 達彦 on 2013/12/29.
6+
//
7+
//
8+
#import "ZipArchive.h"
9+
10+
static NSMutableArray* list = nil;
11+
12+
extern "C"{
13+
14+
15+
void zip(const char*file) {
16+
NSString *zipPath =[NSString stringWithUTF8String:file];
17+
18+
ZipArchive* zip = [[ZipArchive alloc] init];
19+
20+
21+
[zip CreateZipFile2:zipPath];
22+
23+
for(int i=0; i<list.count; i++)
24+
{
25+
26+
NSString* filePath = [list objectAtIndex:i];
27+
NSString* fileName = [filePath lastPathComponent];
28+
[zip addFileToZip:filePath newname:fileName];
29+
}
30+
31+
[zip CloseZipFile2];
32+
[zip release];
33+
34+
[list removeAllObjects];
35+
[list release];
36+
list = nil;
37+
}
38+
39+
void addZipFile(const char*file)
40+
{
41+
NSString *zipPath =[NSString stringWithUTF8String:file];
42+
43+
if( list == nil){
44+
list = [[NSMutableArray alloc] init];
45+
}
46+
[list addObject: zipPath];
47+
}
48+
49+
void unzip( char*file, char* location)
50+
{
51+
NSString *zipPath =[NSString stringWithUTF8String:file];
52+
NSString *destinationPath = [NSString stringWithUTF8String:location];
53+
54+
ZipArchive* zip = [[ZipArchive alloc] init];
55+
if( [zip UnzipOpenFile:zipPath] )
56+
{
57+
[zip UnzipFileTo:destinationPath overWrite:YES];
58+
[zip UnzipCloseFile];
59+
}
60+
[zip CloseZipFile2];
61+
[zip release];
62+
}
63+
}

UnityEPubReader/Assets/Plugins/iOS/UnityZipFile.mm.meta

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityEPubReader/Assets/Scenes.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
28.1 KB
Binary file not shown.

UnityEPubReader/Assets/Scenes/Ebook2d.unity.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityEPubReader/Assets/Scripts.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using UnityEngine;
2+
using UnityEngine.UI;
3+
using System.Collections;
4+
using UEPub;
5+
6+
public class EbookRenderer : MonoBehaviour {
7+
public Text displayText;
8+
public TextAsset testBook;
9+
10+
//private EpubBook epubBook;
11+
12+
// Use this for initialization
13+
void Start () {
14+
OpenEbookFile ();
15+
}
16+
17+
void OpenEbookFile(){
18+
// Opening a book
19+
//epubBook = EpubReader.OpenBook("austen-pride-and-prejudice-illustrations.epub");
20+
//EpubChapter chapter = epubBook.Chapters [0];
21+
//displayText.text = chapter.HtmlContent;
22+
var epub = new UEPubReader ("Assets/Books/austen-pride-and-prejudice-illustrations.epub");
23+
Debug.Log (epub.epubFolderLocation);
24+
}
25+
}

UnityEPubReader/Assets/Scripts/EbookRenderer.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Xml;
5+
using System.IO;
6+
using System.Text;
7+
8+
namespace UEPub{
9+
public class UEPubReader {
10+
11+
public string epubFolderLocation { get; private set; }
12+
13+
public Dictionary<string, string> chapters;
14+
15+
private string opfFileString;
16+
17+
public UEPubReader(string file){
18+
var fileArray = file.Split('.');
19+
20+
if (fileArray [fileArray.Length - 1].ToLower() != "epub") {
21+
Debug.LogErrorFormat ("The file {0} is not a .epub file", file);
22+
return;
23+
}
24+
25+
fileArray = string.Join (".", fileArray, 0, fileArray.Length - 1).Split (System.IO.Path.DirectorySeparatorChar);
26+
var folderName = fileArray[fileArray.Length - 1];
27+
28+
epubFolderLocation = Application.temporaryCachePath + "/" + folderName;
29+
30+
ZipUtil.Unzip ( file, epubFolderLocation);
31+
}
32+
33+
private void ParseContainer(){
34+
var containerFile = epubFolderLocation + "/META-INF/container.xml";
35+
36+
XmlDocument doc = new XmlDocument ();
37+
doc.Load (containerFile);
38+
39+
XmlNode rootFile =
40+
doc.SelectSingleNode("/container/rootfiles/rootfile");
41+
opfFileString = rootFile.Attributes ["full-path"].InnerText;
42+
}
43+
}
44+
}

UnityEPubReader/Assets/Scripts/UEPubReader.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
m_EditorVersion: 5.2.0f3
2+
m_StandardAssetsVersion: 0
Binary file not shown.
4.21 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)