OSDN Git Service

scene2d.ui Disableable interface.
[mikumikustudio/libgdx-mikumikustudio.git] / backends / gdx-backend-iosmonotouch / src / com / badlogic / gdx / backends / ios / IOSFileHandle.java
1 /*******************************************************************************\r
2  * Copyright 2011 See AUTHORS file.\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  * \r
8  *   http://www.apache.org/licenses/LICENSE-2.0\r
9  * \r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  ******************************************************************************/
16 package com.badlogic.gdx.backends.ios;\r
17 \r
18 import java.io.File;\r
19 \r
20 import com.badlogic.gdx.Files.FileType;\r
21 import com.badlogic.gdx.files.FileHandle;\r
22 import com.badlogic.gdx.utils.GdxRuntimeException;\r
23 \r
24 // FIXME see if we can get classpath files to work\r
25 public class IOSFileHandle extends FileHandle {\r
26         public IOSFileHandle (String fileName, FileType type) {\r
27                 super(fileName, type);\r
28                 if(type == FileType.Classpath) {\r
29                         throw new GdxRuntimeException("Classpath files are not supported on iOS, this likely happened because you used the default constructor of BitmapFont.");\r
30                 }\r
31         }\r
32 \r
33         public IOSFileHandle (File file, FileType type) {\r
34                 super(file, type);\r
35                 if(type == FileType.Classpath) {\r
36                         throw new GdxRuntimeException("Classpath files are not supported on iOS, this likely happened because you used the default constructor of BitmapFont.");\r
37                 }\r
38         }\r
39 \r
40         public FileHandle child (String name) {\r
41                 if (file.getPath().length() == 0) return new IOSFileHandle(new File(name), type);\r
42                 return new IOSFileHandle(new File(file, name), type);\r
43         }\r
44 \r
45         public FileHandle parent () {\r
46                 File parent = file.getParentFile();\r
47                 if (parent == null) {\r
48                         if (type == FileType.Absolute)\r
49                                 parent = new File("/");\r
50                         else\r
51                                 parent = new File("");\r
52                 }\r
53                 return new IOSFileHandle(parent, type);\r
54         }\r
55 \r
56         /**\r
57          * This overrides the original method in FileHandle to prevent crashes on iOS. The original method\r
58          * has a fallback to FileType.Classpath when FileType.Internal is used. FileType.Classpath is not\r
59          * supported on iOS.\r
60          * \r
61          * @return  True if the file exists.\r
62          */\r
63         @Override\r
64         public boolean exists () {\r
65                 return file().exists();\r
66         }\r
67 \r
68         public File file () {\r
69                 if (type == FileType.External) return new File(IOSFiles.externalPath, file.getPath());\r
70                 if (type == FileType.Local) return new File(IOSFiles.localPath, file.getPath());\r
71                 return file;\r
72         }\r
73 }