private void CreateImageFile(string timeStamp) { newfile = new Java.IO.File(Android.OS.Environment.GetExternalStoragePublicDirectory( Android.OS.Environment.DirectoryPictures), "cfw" + timeStamp + ".jpg"); mCurrentPhotoPath = newfile.AbsolutePath; if (!newfile.Exists()) { newfile.Mkdir(); if (!newfile.Exists()) { throw new Exception("FIle error!"); } } bool setWritable = false; setWritable = newfile.SetWritable(true, false); }
static public void CopyBinaries() { string folder = Android.App.Application.Context.GetDir("Tor", FileCreationMode.WorldWriteable).AbsolutePath; string path = folder + "/tor"; if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } FileStream TorDest = System.IO.File.Create(path); using (Stream fs = MainActivity.assets.Open("tor")) { fs.CopyTo(TorDest); } TorDest.Close(); Java.IO.File fileTor = new Java.IO.File(folder + "/tor"); bool result = fileTor.SetExecutable(true); result = fileTor.SetReadable(true); result = fileTor.SetWritable(true); //Android.OS.file //Runtime.GetRuntime().Exec("chmod 755 "+path); //it works! //torrc path = folder + "/torrc"; // if (!System.IO.File.Exists(path)) //{ FileStream TorrcDest = System.IO.File.Create(path); using (Stream fs = MainActivity.assets.Open("torrc")) { fs.CopyTo(TorrcDest); } TorrcDest.Close(); // } Java.IO.File torrcfile = new Java.IO.File(folder + "/torrc"); result = torrcfile.SetReadable(true); result = torrcfile.SetWritable(true); StringBuilder text = new StringBuilder(); BufferedReader br = new BufferedReader(new FileReader(path)); System.String line; while ((line = br.ReadLine()) != null) { text.Append(line); text.Append('\n'); } br.Close(); if (text.IndexOf("/data/data/com.thanksoft.masksurfpro/Tor/data") != -1) { string Temp = text.ToString().Replace("/data/data/com.thanksoft.masksurfpro/Tor/data", folder + "/data"); text.Delete(0, text.Length()); text.Append(Temp); } if (text.IndexOf("/data/data/com.thanksoft.masksurfpro/Tor/geoip") != -1) { string Temp = text.ToString().Replace("/data/data/com.thanksoft.masksurfpro/Tor/geoip", folder + "/data"); text.Delete(0, text.Length()); text.Append(Temp); } if (text.IndexOf("/data/data/com.thanksoft.masksurfpro/Tor/geoip6") != -1) { string Temp = text.ToString().Replace("/data/data/com.thanksoft.masksurfpro/Tor/geoip6", folder + "/geoip6"); text.Delete(0, text.Length()); text.Append(Temp); } BufferedWriter bw = new BufferedWriter(new FileWriter(path)); bw.Write(text.ToString()); bw.Close(); //geoip path = folder + "/geoip"; if (!System.IO.File.Exists(path)) { FileStream GeoIPDest = System.IO.File.Create(path); using (Stream fs = MainActivity.assets.Open("geoip")) { fs.CopyTo(GeoIPDest); } GeoIPDest.Close(); } //geoip path = folder + "/geoip6"; if (!System.IO.File.Exists(path)) { FileStream GeoIP6Dest = System.IO.File.Create(path); using (Stream fs = MainActivity.assets.Open("geoip6")) { fs.CopyTo(GeoIP6Dest); } GeoIP6Dest.Close(); } //data folder path = folder + "data"; if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } //Polipo path = folder + "/polipo"; if (!System.IO.File.Exists(path)) { FileStream PolipoDest = System.IO.File.Create(path); using (Stream fs = MainActivity.assets.Open("polipo")) { fs.CopyTo(PolipoDest); } PolipoDest.Close(); Java.IO.File filePolipo = new Java.IO.File(path); filePolipo.SetExecutable(true); } path = folder + "/polipo.conf"; if (!System.IO.File.Exists(path)) { FileStream PolipoConfDest = System.IO.File.Create(path); using (Stream fs = MainActivity.assets.Open("polipo.conf")) { fs.CopyTo(PolipoConfDest); } PolipoConfDest.Close(); } }