aboutsummaryrefslogtreecommitdiff
path: root/games/minimal/mods/default/textures/bubble.png
blob: 3bca7e11cce4c0bfcb34180eea447b6c5e1c6655 (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 10 00 00 00 10 08 06 00 00 00 1f f3 ff .PNG........IHDR................
0020 61 00 00 00 06 62 4b 47 44 00 c0 00 c0 00 c0 1a 9d 07 54 00 00 00 09 70 48 59 73 00 00 0b 13 00 a....bKGD.........T....pHYs.....
0040 00 0b 13 01 00 9a 9c 18 00 00 00 07 74 49 4d 45 07 dd 06 13 0f 12 0e 3b 88 b2 69 00 00 00 9e 49 ............tIME.......;..i....I
0060 44 41 54 38 cb cd 92 c1 0d 04 21 08 45 c1 6c 1f 5a 05 37 db b0 1d a9 c7 32 9c 93 5d 68 25 ec c9 DAT8......!.E.l.Z.7.....2..]h%..
0080 19 43 64 b2 93 6c b2 cb 11 79 fc 1f fc 00 7f 5b bd cb 59 bd 8b 58 73 2f dd 10 11 19 03 20 a5 83 .Cd..l...y.....[..Y..Xs/........
00a0 f5 42 ef 01 10 11 4d d5 a9 46 54 f3 aa 4e 54 33 51 cd d3 d5 ca a0 56 49 e9 e0 d6 22 ef 5c 00 00 .B....M..FT..NT3Q.....VI...".\..
00c0 94 12 39 84 cb 05 3e 81 77 4b dc 6c 7a 7f 0d dc c1 7a d6 e9 c7 31 9e fd 96 d3 a0 a5 de 5a e4 9d ..9...>.wK.lz....z...1.......Z..
00e0 c8 b9 20 04 c4 52 a2 09 4f c8 3c e2 5d 06 d6 e3 e9 2c e0 a7 41 da c1 5f 89 f2 ef eb 0d c1 a7 8f .....R..O.<.]....,..A.._........
0100 7d d4 2f 8c 9d 00 00 00 00 49 45 4e 44 ae 42 60 82 }./......IEND.B`.
a id='n57' href='#n57'>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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
package net.minetest.minetest;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Vector;
import java.util.Iterator;
import java.lang.Object;

import android.app.Activity;
import android.content.res.AssetFileDescriptor;

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Display;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.graphics.Rect;
import android.graphics.Paint;
import android.text.TextPaint;

public class MinetestAssetCopy extends Activity
{
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.assetcopy);
		
		m_ProgressBar = (ProgressBar) findViewById(R.id.progressBar1);
		m_Filename = (TextView) findViewById(R.id.textView1);
		
		Display display = getWindowManager().getDefaultDisplay();
		m_ProgressBar.getLayoutParams().width = (int) (display.getWidth() * 0.8);
		m_ProgressBar.invalidate();
		
		/* check if there's already a copy in progress and reuse in case it is*/
		MinetestAssetCopy prevActivity = 
				(MinetestAssetCopy) getLastNonConfigurationInstance();
		if(prevActivity!= null) {
			m_AssetCopy = prevActivity.m_AssetCopy;
		}
		else {
			m_AssetCopy = new copyAssetTask();
			m_AssetCopy.execute();
		}
	}
	
	/* preserve asset copy background task to prevent restart of copying */
	/* this way of doing it is not recommended for latest android version */
	/* but the recommended way isn't available on android 2.x */
	public Object onRetainNonConfigurationInstance()
	{
		return this;
	}
	
	ProgressBar m_ProgressBar;
	TextView m_Filename;
	
	copyAssetTask m_AssetCopy;
	
	private class copyAssetTask extends AsyncTask<String, Integer, String>
	{
		private long getFullSize(String filename)
		{
			long size = 0;
			try {
				InputStream src = getAssets().open(filename);
				byte[] buf = new byte[4096];
				
				int len = 0;
				while ((len = src.read(buf)) > 0)
				{
					size += len;
				}
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return size;
		}

		@Override
		protected String doInBackground(String... files)
		{
			m_foldernames  = new Vector<String>();
			m_filenames    = new Vector<String>();
			m_tocopy       = new Vector<String>();
			m_asset_size_unknown = new Vector<String>();
			String baseDir = 
					Environment.getExternalStorageDirectory().getAbsolutePath()
					+ "/";
			
			
			// prepare temp folder
			File TempFolder = new File(baseDir + "Minetest/tmp/");
			
			if (!TempFolder.exists())
			{
				TempFolder.mkdir();
			}
			else {
				File[] todel = TempFolder.listFiles();
				
				for(int i=0; i < todel.length; i++)
				{
					Log.v("MinetestAssetCopy","deleting: " + todel[i].getAbsolutePath());
					todel[i].delete();
				}
			}
			
			// add a .nomedia file
			try {
				OutputStream dst = new FileOutputStream(baseDir + "Minetest/.nomedia");
				dst.close();
			} catch (IOException e) {
				Log.e("MinetestAssetCopy","Failed to create .nomedia file");
				e.printStackTrace();
			}
			
			
			// build lists from prepared data
			BuildFolderList();
			BuildFileList();
			
			// scan filelist
			ProcessFileList();
			
			// doing work
			m_copy_started = true;
			m_ProgressBar.setMax(m_tocopy.size());
			
			for (int i = 0; i < m_tocopy.size(); i++)
			{
				try
				{
					String filename = m_tocopy.get(i);
					publishProgress(i);
					
					boolean asset_size_unknown = false;
					long filesize = -1;
					
					if (m_asset_size_unknown.contains(filename))
					{
						File testme = new File(baseDir + "/" + filename);
						
						if(testme.exists())
						{
							filesize = testme.length();
						}
						asset_size_unknown = true;
					}
					
					InputStream src;
					try
					{
						src = getAssets().open(filename);
					} catch (IOException e) {
						Log.e("MinetestAssetCopy","Copying file: " + filename + " FAILED (not in assets)");
						e.printStackTrace();
						continue;
					}
					
					// Transfer bytes from in to out
					byte[] buf = new byte[1*1024];
					int len = src.read(buf, 0, 1024);
					
					/* following handling is crazy but we need to deal with    */
					/* compressed assets.Flash chips limited livetime due to   */
					/* write operations, we can't allow large files to destroy */
					/* users flash.                                            */
					if (asset_size_unknown)
					{
						if ( (len > 0) && (len < buf.length) && (len == filesize))
						{
							src.close();
							continue;
						}
						
						if (len == buf.length)
						{
							src.close();
							long size = getFullSize(filename);
							if ( size == filesize)
							{
								continue;
							}
							src = getAssets().open(filename);
							len = src.read(buf, 0, 1024);
						}
					}
					if (len > 0)
					{
						int total_filesize = 0;
						OutputStream dst;
						try
						{
							dst = new FileOutputStream(baseDir + "/" + filename);
						} catch (IOException e) {
							Log.e("MinetestAssetCopy","Copying file: " + baseDir +
							"/" + filename + " FAILED (couldn't open output file)");
							e.printStackTrace();
							src.close();
							continue;
						}
						dst.write(buf, 0, len);
						total_filesize += len;
						
						while ((len = src.read(buf)) > 0)
						{
							dst.write(buf, 0, len);
							total_filesize += len;
						}
						
						dst.close();
						Log.v("MinetestAssetCopy","Copied file: " +
									m_tocopy.get(i) + " (" + total_filesize +
									" bytes)");
					}
					else if (len < 0)
					{
						Log.e("MinetestAssetCopy","Copying file: " +
								m_tocopy.get(i) + " failed, size < 0");
					}
					src.close();
				} 
				catch (IOException e)
				{
					Log.e("MinetestAssetCopy","Copying file: " +
							m_tocopy.get(i) + " failed");
					e.printStackTrace();
				}
			}
			return "";
		}
		
		
		/**
		 * update progress bar
		 */
		protected void onProgressUpdate(Integer... progress)
		{
			
			if (m_copy_started)
			{
				boolean shortened = false;
				String todisplay = m_tocopy.get(progress[0]);
				m_ProgressBar.setProgress(progress[0]);
				m_Filename.setText(todisplay);
			}
			else
			{
				boolean shortened = false;
				String todisplay = m_Foldername;
				String full_text = "scanning " + todisplay + " ...";
				m_Filename.setText(full_text);
			}
		}
		
		/**
		 * check al files and folders in filelist
		 */
		protected void ProcessFileList()
		{
			String FlashBaseDir = 
					Environment.getExternalStorageDirectory().getAbsolutePath();
			
			Iterator itr = m_filenames.iterator();
			
			while (itr.hasNext())
			{
				String current_path = (String) itr.next();
				String FlashPath = FlashBaseDir + "/" + current_path;
				
				if (isAssetFolder(current_path))
				{
					/* store information and update gui */
					m_Foldername = current_path;
					publishProgress(0);
					
					/* open file in order to check if it's a folder */
					File current_folder = new File(FlashPath);
					if (!current_folder.exists())
					 {
						if (!current_folder.mkdirs())
						{
							Log.e("MinetestAssetCopy","\t failed create folder: " +
									FlashPath);
						}
						else
						{
							Log.v("MinetestAssetCopy","\t created folder: " +
									FlashPath);
						}
					}
					
					continue;
				}
				
				/* if it's not a folder it's most likely a file */
				boolean refresh = true;
				
				File testme = new File(FlashPath);
				
				long asset_filesize = -1;
				long stored_filesize = -1;
				
				if (testme.exists())
				{
					try
					{
						AssetFileDescriptor fd = getAssets().openFd(current_path);
						asset_filesize         = fd.getLength();
						fd.close();
					} 
					catch (IOException e)
					{
						refresh = true;
						m_asset_size_unknown.add(current_path);
						Log.e("MinetestAssetCopy","Failed to open asset file \"" +
								FlashPath + "\" for size check");
					}
					
					stored_filesize = testme.length();
					
					if (asset_filesize == stored_filesize)
					{
						refresh = false;
					}
					
				}
				
				if (refresh)
				{
					m_tocopy.add(current_path);
				}
			}
		}
		
		/**
		 * read list of folders prepared on package build
		 */
		protected void BuildFolderList()
		{
			try
			{
				InputStream is = getAssets().open("index.txt");
				BufferedReader reader = new BufferedReader(new InputStreamReader(is));
		
				String line = reader.readLine();
				while (line != null)
				{
					m_foldernames.add(line);
					line = reader.readLine();
				}
				is.close();
			} catch (IOException e1)
			{
				Log.e("MinetestAssetCopy","Error on processing index.txt");
				e1.printStackTrace();
			}
		}
		
		/**
		 * read list of asset files prepared on package build
		 */
		protected void BuildFileList()
		{
			long entrycount = 0;
			try
			{
				InputStream is = getAssets().open("filelist.txt");
				BufferedReader reader = new BufferedReader(new InputStreamReader(is));
		
				String line = reader.readLine();
				while (line != null)
				{
					m_filenames.add(line);
					line = reader.readLine();
					entrycount ++;
				}
				is.close();
			}
			catch (IOException e1)
			{
				Log.e("MinetestAssetCopy","Error on processing filelist.txt");
				e1.printStackTrace();
			}
		}
		
		protected void onPostExecute (String result)
		{
			finish();
		}
		
		protected boolean isAssetFolder(String path)
		{
			return m_foldernames.contains(path);
		}
		
		boolean m_copy_started = false;
		String m_Foldername = "media";
		Vector<String> m_foldernames;
		Vector<String> m_filenames;
		Vector<String> m_tocopy;
		Vector<String> m_asset_size_unknown;
	}
}