Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PathsHelper.java « play « blender « org « src « app « android « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 673fdebd601321f3d9bc9c53773b4813657bd380 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package org.blender.play;

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.*;
import android.util.Log;

public class PathsHelper {

	static String BaseAppDir;
	static {
		BaseAppDir = null;
		
		
	}
	
	
	static public String getBaseAppDir(Context context)
	{
		if(BaseAppDir == null)
		{
			BaseAppDir = context.getFilesDir().getPath();
			BaseAppDir = BaseAppDir.substring(0, BaseAppDir.lastIndexOf("/")+1);
			
			
		}
		
		return BaseAppDir;
		
	}
	
	static public String getFileName(String path)
	{
		
		
		return path.substring(path.lastIndexOf("/")+1);
	}
	
	public static void InstallFile(InputStream inputStream, String basepath)
	{
        try
        {
	        ZipInputStream zip = new ZipInputStream(
	        						new BufferedInputStream(
	        								inputStream));
	        try {
	        	byte[] buff = new byte[4096];
	        	
	            ZipEntry entry;
	            while ((entry = zip.getNextEntry()) != null) {
	                
	                String filename = entry.getName();
	                
	                if(filename != null)
	                {
	                	if(entry.isDirectory())
	                	{
	                		if(!new File(basepath + filename).mkdir())
	                			Log.e("Blender", "Cannot create "+filename+" dir.");
	                		
	                		
	                	} else
	                	{
		                	FileOutputStream outfile = new FileOutputStream(basepath + filename);
		                	try{	  
		                		Log.i("Blender", "Installing " + filename);
		                		
				                int count;
				                while ((count = zip.read(buff)) != -1) {
				                	outfile.write(buff, 0, count);
				                };
			                
		                	} finally {
		                		outfile.close();
		        	        }
	                	}
	                }
	            }
	        } finally {
	        	zip.close();
	        }
        
        
        }
        catch (Exception e) 
        {
        	Log.w("Blender", "Error reading file: " + e);
        }
		
		
		
	}
	
	
	
	
	
	
	static public boolean installIfNeeded(Context context)
	{
		try {
			PackageInfo pack = context.getPackageManager().getPackageInfo(context.getApplicationContext().getPackageName(), 0);
			String apkver =pack.versionName;
			
			String curver = "0.0";
			
			try{
				FileInputStream fin = new FileInputStream(getBaseAppDir(context)+"version.txt");
				BufferedInputStream bin = new BufferedInputStream(fin);
				DataInputStream din = new DataInputStream(bin);
				
				if(din.available()>0)
				{
					curver = din.readLine();
				}
				
				din.close();
				bin.close();
				fin.close();
				
				
			} catch (Exception e){//Catch exception if any
				  
			}
		
		
			if(!curver.equals(apkver))
			{
				try {
					InstallFile(context.getAssets().open("internalfiles.zip"), getBaseAppDir(context));
				} catch (IOException e1) {

				}
				
				
			 try{
					FileWriter fout = new FileWriter(getBaseAppDir(context)+"version.txt");
					BufferedWriter out = new BufferedWriter(fout);
					out.write(apkver);
					out.close();
				}catch (Exception e)
				{


				}
				
				return true;
			}
			

			
			
		
		} catch (NameNotFoundException e) {
			
		}
		
		return false;	
	}
	
}