Related
Hi all,
Does anyone know how to retrive (identify) the system name of the Storage Card using .Net C.F. and Visual Basic language?
This is because often changig the WM version or the localization of the device, can also change the name of the Storage Card (with related "Path not found" error in the program).
Thanks for help
using C#.net
Code:
private static string GetStorageCardPath()
{
DirectoryInfo di = new DirectoryInfo(@"\");
FileSystemInfo[] fsi = di.GetFileSystemInfos();
foreach (FileSystemInfo fileSystemInfo in fsi)
{
if ((fileSystemInfo.Attributes & FileAttributes.Temporary) == FileAttributes.Temporary)
{
return fileSystemInfo.FullName;
}
}
return null;
}
and with convert csharp to vb in VB.net
Code:
Private Shared Function GetStorageCardPath() As String
Dim di As New DirectoryInfo("\")
Dim fsi As FileSystemInfo() = di.GetFileSystemInfos()
For Each fileSystemInfo As FileSystemInfo In fsi
If (fileSystemInfo.Attributes And FileAttributes.Temporary) = FileAttributes.Temporary Then
Return fileSystemInfo.FullName
End If
Next
Return Nothing
End Function
Thanks HeliosDev!
Halo Guyz!
Im trying to create my first simple program in visual studio 2008 with C3 language. I want to create just a button in the form and here is the code i use
Code:
private void button1_Click(object sender, EventArgs e)
{
button1.Text = "Yes!";
}
When i m going to Deploy it in my WM6 Device (HP iPaq 514) It returns me an NotSupportedException Error for the button. In this line of the Form1.Designer.cs
Does anyone why this happens ? Is possible that my phone can't create a new button ? Can anyone tell me how to fix this problem ?
Thanks in advanced!
Depending on where that function is located in your code, you may not have full access to the Button1 control. Here is what you should try:
Code:
private void button1_Click(object sender, EventArgs e)
{
Button myButton = (Button) sender;
myButton.Text = "CLICK"
}
I try that you said but stills give me the same error :
Here is an image ... Maybe helps you understand more this problem...
h**p://img411.imageshack.us/img411/4362/errorh.png
Hi there,
I'm having a big issue, when trying to remove an XElement from an XML file created in IsolatedStorage.
--------------------------------------------------------------------------------------------
Code to CREATE the XML file
Dim File_to_Create As String = "Tracks.xml"
Dim file As XDocument = <?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlnsd="urn:schemas-microsoft-comfficedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Cartridges.xsd" generated="2010-11-23T14:26:55">
<Carts>
<CART_NAME>First</CART_NAME>
<CART_COLOR>White</CART_COLOR>
</Carts>
<Carts>
<CART_NAME>Second</CART_NAME>
<CART_COLOR>Black</CART_COLOR>
</Carts>
</dataroot>
Dim isoStore As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
Try
If isoStore.FileExists(File_to_Create) Then
MessageBox.Show(File_to_Create + " TRUE")
Else
MessageBox.Show(File_to_Create + " FALSE")
Dim oStream As New IsolatedStorageFileStream(File_to_Create, FileMode.Create, isoStore)
Dim writer As New StreamWriter(oStream)
writer.WriteLine(file)
writer.Close()
MessageBox.Show("OK")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
'open selected file
Dim isoStream As IsolatedStorageFileStream
isoStream = New IsolatedStorageFileStream(File_to_Create, System.IO.FileMode.Open, System.IO.FileAccess.Read, isoStore)
Dim XML_File As XDocument = XDocument.Load(isoStream)
Dim Cart_Query As System.Collections.IEnumerable = From query In XML_File.Descendants("Carts") Order By _
CStr(query.Element("CART_NAME")) Descending, CStr(query.Element("CART_NAME"))
Select New Class_Cartridge_Data With {.Cart_Name = CStr(query.Element("CART_NAME")), _
.Cart_Color = CStr(query.Element("CART_COLOR"))}
Me.ListBox_Cartridges.ItemsSource = Cart_Query
isoStore.Dispose()
isoStream.Close()
End Try
--------------------------------------------------------------------------------------------
Code to ADD / EDIT XElement
Dim File_to_Create As String = "Tracks.xml"
Dim XML_IsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()
' Check that the file exists if not create it
If Not (XML_IsolatedStorage.FileExists(File_to_Create)) Then
Return
End If
Dim XML_StreamReader As New StreamReader(XML_IsolatedStorage.OpenFile(File_to_Create, FileMode.Open, FileAccess.Read))
Dim XML_Document As XDocument = XDocument.Parse(XML_StreamReader.ReadToEnd())
XML_StreamReader.Close()
' Update the element if it exist or create it if it doesn't
Dim XML_XElement As XElement = XML_Document.Descendants("Carts").Where(Function(c) c.Element("CART_NAME").Value.Equals("First")).FirstOrDefault()
If XML_XElement IsNot Nothing Then
XML_XElement.SetElementValue("CART_NAME", "Third")
Else
' Add new
Dim newProgress As New XElement("Cartridges", New XElement("CART_NAME", "Fourth"), New XElement("CART_COLOR", "Blue"))
Dim rootNode As XElement = XML_Document.Root
rootNode.Add(newProgress)
End If
Using XML_StreamWriter As New StreamWriter(XML_IsolatedStorage.OpenFile(File_to_Create, FileMode.Open, FileAccess.Write))
XML_StreamWriter.Write(XML_Document.ToString())
XML_StreamWriter.Close()
End Using
--------------------------------------------------------------------------------------------
Now my issue and request for some help!
If I use
XML_XElement.Remove
then the following exception is raised whenever I try to "refresh" the bounded ListBox
System.Xml.XmlException was unhandled
LineNumber=37
LinePosition=12
Message=Data at the root level is invalid. Line 37, position 12.
SourceUri=""
StackTrace:
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(Int32 res, String resString, String[] args)
at System.Xml.XmlTextReaderImpl.Throw(Int32 res, String resString)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at System.Xml.Linq.XDocument.Load(Stream stream, LoadOptions options)
at System.Xml.Linq.XDocument.Load(Stream stream)
at ListBox_Data_from_XML_LINQ.MainPage.Button_Create_XML_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
InnerException:
--------------------------------------------------------------------------------------------
In short, I can add or edit, but cannot DELETE an XElement...
Any ideas?
Thanks in advance!
Can you post the code you are using for XElement.Remove and use code tags so the formatting is right. Its the # button on the post toolbar.
Ren13B said:
Can you post the code you are using for XElement.Remove and use code tags so the formatting is right. Its the # button on the post toolbar.
Click to expand...
Click to collapse
Well, I did nothing special, just the XML_Element.remove, instead of adding a new xelement.
Then the error raises whenever I try to reopen the XML file.
My point is, how can I delete an specific xelement?
As far as I know, the following code should work
Code:
Dim XML_XElement As XElement = XML_Document.Descendants("Carts").Where(Function(c ) c.Element("CART_NAME").Value.Equals("First")).Firs tOrDefault()
If XML_XElement IsNot Nothing Then
XML_XElement.SetElementValue("CART_NAME", "Third")
Else
' remove the selected record
XML_XElement.Remove
End If
Honestly I don't know if the foregoing code is correct or if the issue is related to how WP7 handles the removal thus corrupting the original file.
Please let me know if you need anything else.
Any help is very appreciated!
PS: Thanks for the other replies, helped a lot!
Here's how I did it in c#. My xml file is very different than yours so the query will be different but the important parts are where you load and close the file streams and then write.
Code:
//Get users private store info
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isoStream;
//open selected file
isoStream = new IsolatedStorageFileStream(list, System.IO.FileMode.Open, System.IO.FileAccess.Read, isoStore);
XDocument xml = XDocument.Load(isoStream);
isoStream.Close();
//Find section
XElement sectionElement = xml.Descendants("section").Where(c => c.Attribute("name").Value.Equals(groupn)).FirstOrDefault();
//Find item and remove it
sectionElement.Elements("setting").Where(c => c.Attribute("name").Value.Equals(litem)).FirstOrDefault().Remove();
isoStream.Close(); //Seems unnecessary but it's needed.
//Write xml file
isoStream = new IsolatedStorageFileStream(list, FileMode.Create, FileAccess.Write, isoStore);
xml.Save(isoStream);
isoStream.Close();
Thanks again for your help, greatly appreciated.
However I'm still getting the same error.
Sorry for asking, but are you getting any errors when deleting in WP7 ?
My knowledge on XML is extremely new and I'm sure that I'm making some mistakes somewhere...
But so far, I cannot get past the same exception.
Seems that the XML gots "corrupted" after the delete operation.
On the other hand, if is not too much to ask for, using my current code, how will handle the delete of the selected record?
Thanks!
I have no problem at all removing elements in c#. I don't have vb support even installed right now. If you think it's a bug you should post on the forums at http://forums.create.msdn.com/forums/98.aspx
Ren13B said:
I have no problem at all removing elements in c#. I don't have vb support even installed right now. If you think it's a bug you should post on the forums at http://forums.create.msdn.com/forums/98.aspx
Click to expand...
Click to collapse
Problem is my country is not listed so I cannot register...
Here is the C# version of my current code for adding/editing
Code:
public static void ADD_XML_Record()
{
string File_to_Create = "Tracks.xml";
var XML_IsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
// Check that the file exists if not create it
if (! (XML_IsolatedStorage.FileExists(File_to_Create)))
{
return;
}
StreamReader XML_StreamReader = new StreamReader(XML_IsolatedStorage.OpenFile(File_to_Create, FileMode.Open, FileAccess.Read));
XDocument XML_Document = XDocument.Parse(XML_StreamReader.ReadToEnd());
XML_StreamReader.Close();
// Update the element if it exist or create it if it doesn't
XElement XML_XElement = XML_Document.Descendants("Carts").Where((c) => c.Element["CART_NAME"].Value.Equals("dd")).FirstOrDefault();
if (XML_XElement != null)
{
XML_XElement.SetElementValue("CART_NAME", "bbbbb");
}
else
{
// Add new
XElement newProgress = new XElement("Carts", new XElement("CART_NAME", "dd"), new XElement("CART_COLOR", "ff"));
XElement rootNode = XML_Document.Root;
rootNode.Add(newProgress);
}
using (StreamWriter XML_StreamWriter = new StreamWriter(XML_IsolatedStorage.OpenFile(File_to_Create, FileMode.Open, FileAccess.Write)))
{
XML_StreamWriter.Write(XML_Document.ToString());
XML_StreamWriter.Close();
}
}
I tried your code but I'm having a bad time making it to work.
If not a big deal, please could you tell me how to modify it ?
I mean, if a record is found, instead of editing, to remove it?
Honestly I'm stuck and any help is more than apprecisted!
Ren13B said:
I have no problem at all removing elements in c#. I don't have vb support even installed right now. If you think it's a bug you should post on the forums at http://forums.create.msdn.com/forums/98.aspx
Click to expand...
Click to collapse
Ren,
Just to say thank you for your last code. I made a little mod and now it works ok!
Thanks a lot for helping me out!
Hi everyone,
Today i come here with ideas.....
which is
HTC RUU in .NET Flavour
you can browse for nbh file, not locked at current folder with this tool
the project has its site located at: http://htcruunet.codeplex.com
i hope anyone want to collaborate in this project, because, my c# skill is SEVERLY WEAK.
Dev. Status:
-Prototype (UI Design)
aramadsanar said:
....Today i come here with ideas.....
Click to expand...
Click to collapse
Something like that:
Whitestone Advanced ROM Update Utility
Kovsky Advanced ROM Update Utility
Topaz Advanced ROM Update Utility
Blackstone Advanced ROM Update Utility
Mozart Advanced ROM Update Utility
LEO Advanced ROM Update Utility
by Barin????....
The main benefit is .Net 4 (Barin used 3.5) and possibility not to put nbh to one folder with the flasher?
Or again - adding "eye candy" features? Maybe pink dots on main window?
Funny
AndrewSh said:
Something like that:
Whitestone Advanced ROM Update Utility
Kovsky Advanced ROM Update Utility
Topaz Advanced ROM Update Utility
Blackstone Advanced ROM Update Utility
Mozart Advanced ROM Update Utility
LEO Advanced ROM Update Utility
by Barin????....
The main benefit is .Net 4 (Barin used 3.5) and possibility not to put nbh to one folder with the flasher?
Or again - adding "eye candy" features? Maybe pink dots on main window?
Funny
Click to expand...
Click to collapse
don't talk sinister here
---------------------------------------------------------------------------
ok, the differences is, i aimed to make it open source, but, barin's closed
so, the benefit is, people can learn how RUU works, not just a frickin' eye candy.
that's it
---------------------------------------------------------------------------
come on, grow up, we're here to learn, develop, share, not to talk sinister
This "program" does NOTHING. STOP SPAMMING FORUM WITH YOUR USELESS PROGRAMS.
Entire source code:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace RUUNET
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button2.Enabled = false;
}
private void ignoreRUURequirementsToolStripMenuItem_Click(object sender, EventArgs e)
{
checkBox2.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
}
public void UpdateDevice()
{
if (checkBox2.Enabled == false)
{
FlashNbh();
}
else
{
GetDeviceModel();
GetDeviceCID();
GetBattery();
VerifyRomWithDeviceModel();
FlashNbh();
}
}
public void GetDeviceCID()
{
}
public void GetBattery()
{
}
public void GetDeviceModel()
{
}
public void VerifyRomWithDeviceModel()
{
}
public void FlashNbh()
{
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = " ";
openFileDialog1.Title = "Choose ROM Image to Flash";
openFileDialog1.ShowDialog();
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
if (openFileDialog1.FileName.Contains(".nbh"))
{
button2.Enabled = true;
textBox1.Text = openFileDialog1.FileName.ToString();
}
else
{
NBHError();
}
}
private void enableRUURequirementsToolStripMenuItem_Click(object sender, EventArgs e)
{
checkBox2.Enabled = true;
}
public void NBHError()
{
MessageBox.Show("The file you selected is not NBH File", "Not NBH File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
Useless guy, but actually the idea is cool - kinda: "guys, I will start VS project and make interface. The rest is almost nothing - code and full functionality - should be done by you guys - and you will be co-authors... Maybe....". Nice!
Useless guy said:
This "program" does NOTHING. STOP SPAMMING FORUM WITH YOUR USELESS PROGRAMS.
Entire source code:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace RUUNET
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button2.Enabled = false;
}
private void ignoreRUURequirementsToolStripMenuItem_Click(object sender, EventArgs e)
{
checkBox2.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
}
public void UpdateDevice()
{
if (checkBox2.Enabled == false)
{
FlashNbh();
}
else
{
GetDeviceModel();
GetDeviceCID();
GetBattery();
VerifyRomWithDeviceModel();
FlashNbh();
}
}
public void GetDeviceCID()
{
}
public void GetBattery()
{
}
public void GetDeviceModel()
{
}
public void VerifyRomWithDeviceModel()
{
}
public void FlashNbh()
{
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = " ";
openFileDialog1.Title = "Choose ROM Image to Flash";
openFileDialog1.ShowDialog();
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
if (openFileDialog1.FileName.Contains(".nbh"))
{
button2.Enabled = true;
textBox1.Text = openFileDialog1.FileName.ToString();
}
else
{
NBHError();
}
}
private void enableRUURequirementsToolStripMenuItem_Click(object sender, EventArgs e)
{
checkBox2.Enabled = true;
}
public void NBHError()
{
MessageBox.Show("The file you selected is not NBH File", "Not NBH File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
Click to expand...
Click to collapse
well, i'm not spamming, i have a working program (WPE4), but, in this case, i only can design the program, but, i got stuck when thinking about SPL commands, so, this is why i made it in codeplex, to make it open source, and collaborate, if you like to collaborate in this project, you're welcome
and, if you think that my project(s) is totally USELESS, then, do not use it, easy, right
Guys, break up!
Quote from his profile
I'm 14 yrs old, and, i'm coordinator & initiator of Advanced WPE. I'm also a ROM Cooker for HTC HD7.
You can contact me by:
Email: [email protected]
Twitter: @aramadsanar
Phone: +628989739611
Click to expand...
Click to collapse
Wow, there is email and even phone, so if you, guys, wanna to help "coordinator & initiator of Advanced WPE & a ROM Cooker for HTC HD7", contact him. Unfortunately, as you see, I'm from russia and the international calls are very expensive for me.
Useless guy said:
Wow, there is email and even phone, so if you, guys, wanna to help "coordinator & initiator of Advanced WPE & a ROM Cooker for HTC HD7", contact him. Unfortunately, as you see, I'm from russia and the international calls are very expensive for me.
Click to expand...
Click to collapse
Unfortunately for me too
@aramadsanar
If you want an advice:
1. Do not import all available assemblies into your project, just use only neccesery.
2. Use "Public" definition only if you want to provide access to your functions or variables from external programs.
3. Avoid default naming of controls - after a few weeks you will forget what is your button for (for example), especially if you plan to change some of its properties programmatically later.
4. If you want to write RUU try to use stock RUU as external executable in your program at first
Good luck!
Useless guy said:
Guys, break up!
Quote from his profile
Wow, there is email and even phone, so if you, guys, wanna to help "coordinator & initiator of Advanced WPE & a ROM Cooker for HTC HD7", contact him. Unfortunately, as you see, I'm from russia and the international calls are very expensive for me.
Click to expand...
Click to collapse
wait, you can mention me, or email me LOL
Great developers all over xda make good guides and awesome mods.but all they do is writing the mod and say copy to bla bla and you are done. This don't create a real developer. I think you should explain the codes to us. If you don't mind some people wanna learn here
True but you should move the thread to the General section.
Deleted
The thread is in its right place....
ya GUIDE Codes shoul be explaind
I know java well, but most of Guides are on Smali language, I don't like copy paste cause I wanna learn it right, So what's the problem in explaining mods
@Jonny pls move this to general section, thanks
If you want to know what smali functions do then download Virtuous Ten Studio by Diamondback and the rest of the Virtuous team then look in the included smali help section.
Jonny said:
If you want to know what smali functions do then download Virtuous Ten Studio by Diamondback and the rest of the Virtuous team then look in the included smali help section.
Click to expand...
Click to collapse
I don't mean the smali basics, I meant explaining mods in depth instead of this Copy-Paste, I will check VTS asap, thanks for suggestion
mohamedrashad said:
I don't mean the smali basics, I meant explaining mods in depth instead of this Copy-Paste, I will check VTS asap, thanks for suggestion
Click to expand...
Click to collapse
With smali you are basically just moving numbers around and calling other methods (invoke and invoke-virtual) - usually you store the result in a register for example v0. Then you've got you're comparison statements like if-ne (if not equal), if-eq (if equal), if-nez (if not equal to zero) etc. Then you can also call resources by using the hex values in public.xml, eg const v4, "0x070000" for example.
Once you know the basic functions and principals of the language then its fairly easy to follow the code of the mods to find out what they're doing and what they're changing.
Jonny said:
With smali you are basically just moving numbers around and calling other methods (invoke and invoke-virtual) - usually you store the result in a register for example v0. Then you've got you're comparison statements like if-ne (if not equal), if-eq (if equal), if-nez (if not equal to zero) etc. Then you can also call resources by using the hex values in public.xml, eg const v4, "0x070000" for example.
Once you know the basic functions and principals of the language then its fairly easy to follow the code of the mods to find out what they're doing and what they're changing.
Click to expand...
Click to collapse
Simpler than Java I should learn it soon
mohamedrashad said:
Simpler than Java I should learn it soon
Click to expand...
Click to collapse
Ha! I wish, to do for example the following in java
Code:
Integer i = 1;
if (i = 0) {
return "wtf is happening!";
} else {
return "everything is normal";
}
in smali would be something like:
Code:
const v1, 0x1
const-string v2, "wtf is happening"
const-string v3, "everything is normal"
if-eqz v1 :cond_0
return v3
:cond_0
return v2
My syntax is probably not correct but this was just something wrote off the top of my head so... :highfive: Point is what you can do relatively easily in java with a couple of lines of code can be a pain in the neck and take up a lot of lines to do in smali - especially with more complex functions.
For example I'd hate to have to try and do something like this in smali (code snippet from an app I've made for my school).
Code:
class LoadNews extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgress = new ProgressDialog(getSherlockActivity());
mProgress.setMessage("Loading news, Please wait...");
mProgress.setIndeterminate(false);
mProgress.setCancelable(true);
mProgress.show();
}
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(AllNewsItemsURL, "GET", params);
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
newsItems = json.getJSONArray(NEWS);
for (int i = 0; i < newsItems.length(); i++) {
JSONObject obj = newsItems.getJSONObject(i);
Integer id = i + 1;
String title = obj.getString(TITLE);
String story = obj.getString(STORY);
String imageSrc = IMAGE_DIR_URL + obj.getString(IMAGE_SRC);
String date = obj.getString(DATE);
story = replace(story, imageSrc);
date = buildDate(date);
if (id > dbhandler.getNewsCount()) {
dbhandler.addNews(new News(id, title, story, imageSrc, date));
} else {
dbhandler.updateNews(new News(id, title, story, imageSrc, date));
}
if (isCancelled() || FlagCancelled) break;
}
} else {
Log.e("JSON Response", "success == 0");
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
mProgress.dismiss();
getSherlockActivity().runOnUiThread(new Runnable() {
public void run() {
getNewsList();
}
});
}
}
Jonny said:
Ha! I wish, to do for example the following in java
Code:
Integer i = 1;
if (i = 0) {
return "wtf is happening!";
} else {
return "everything is normal";
}
in smali would be something like:
Code:
const v1, 0x1
const-string v2, "wtf is happening"
const-string v3, "everything is normal"
if-eqz v1 :cond_0
return v3
:cond_0
return v2
My syntax is probably not correct but this was just something wrote off the top of my head so... :highfive: Point is what you can do relatively easily in java with a couple of lines of code can be a pain in the neck and take up a lot of lines to do in smali - especially with more complex functions.
For example I'd hate to have to try and do something like this in smali (code snippet from an app I've made for my school).
Code:
class LoadNews extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgress = new ProgressDialog(getSherlockActivity());
mProgress.setMessage("Loading news, Please wait...");
mProgress.setIndeterminate(false);
mProgress.setCancelable(true);
mProgress.show();
}
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(AllNewsItemsURL, "GET", params);
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
newsItems = json.getJSONArray(NEWS);
for (int i = 0; i < newsItems.length(); i++) {
JSONObject obj = newsItems.getJSONObject(i);
Integer id = i + 1;
String title = obj.getString(TITLE);
String story = obj.getString(STORY);
String imageSrc = IMAGE_DIR_URL + obj.getString(IMAGE_SRC);
String date = obj.getString(DATE);
story = replace(story, imageSrc);
date = buildDate(date);
if (id > dbhandler.getNewsCount()) {
dbhandler.addNews(new News(id, title, story, imageSrc, date));
} else {
dbhandler.updateNews(new News(id, title, story, imageSrc, date));
}
if (isCancelled() || FlagCancelled) break;
}
} else {
Log.e("JSON Response", "success == 0");
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
mProgress.dismiss();
getSherlockActivity().runOnUiThread(new Runnable() {
public void run() {
getNewsList();
}
});
}
}
Click to expand...
Click to collapse
i'm just wondering why apk tool don't give us Java code The development would be easier
mohamedrashad said:
i'm just wondering why apk tool don't give us Java code The development would be easier
Click to expand...
Click to collapse
That's to do with the Dalvik VM android apps run on. If you compiled standard java files (.java) for a standard java applet then those files would be compiled into .class files (which can be "reverse engineered" - though not particularly well and all reverse engineer software available for java currently should be used for guidance only as the code they output is nowhere near the original.
For android apps, these .class files are further compiled into a dalvik executable file with extension .dex - in an apk file this is called classes.dex. You can think of a classes.dex file as a compiled .exe file - you can't easily get readable/correct source of it. Exe files are therefore reverse engineered into their byte-code which is in a low-level language called Assembly Language (ASM).
Dalvik executables work in much the same way that they can be decompiled to their byte-code, which allows them to be edited without having the full source - unlike using a java decompiler, they give correct code for the language they are written in. The dalvik byte-code is the smali language so you can think of smali as the dalvik equivalent of ASM.
In short term, smali is editable and can be recompiled and run with no problems whereas code produced by current java decompilers cannot be used to make changes and then recompiled due to incorrect code given, so in this instance it was better for apktool to give a smali output :good:
mohamedrashad said:
i'm just wondering why apk tool don't give us Java code The development would be easier
Click to expand...
Click to collapse
@Jonny
Have a look at this tool I found - maybe useful maybe not
http://forum.xda-developers.com/showthread.php?p=52853769
marcussmith2626 said:
@Jonny
Have a look at this tool I found - maybe useful maybe not
http://forum.xda-developers.com/showthread.php?p=52853769
Click to expand...
Click to collapse
That doesn't seem too bad considering the likes of JAD and JD-GUI, however, I can still 100% guarantee that if you put that into Android Studio (or Eclipse but I prefer AS), it would not compile
Best to use decompiled java as a guideline or to search for methods you want to make mods out of - eg increasing the maximum number of pages in the HTC Sense 6.0 launcher (Prism.apk) you search for the method getMaxPageCount() in the decompiled java code, have a look at what the java was like then find out where to change the values and then do the actual mod in smali.
marcussmith2626 said:
@Jonny
Have a look at this tool I found - maybe useful maybe not
http://forum.xda-developers.com/showthread.php?p=52853769
Click to expand...
Click to collapse
These apps (java decompiler) are good to learn some tricks in apps but non give a ready-to-import Eclipse project which make them 75% useless
mohamedrashad said:
These apps (java decompiler) are good to learn some tricks in apps but non give a ready-to-import Eclipse project which make them 75% useless
Click to expand...
Click to collapse
I dont have any experience of programming so I dont know the use of these things but I spose Its interesting to compare
My main expertise is end user software/hardware support and repair for pcs/laptops - I just look at android as a hobby for fun as something different
marcussmith2626 said:
I dont have any experience of programming so I dont know the use of these things but I spose Its interesting to compare
My main expertise is end user software/hardware support and repair for pcs/laptops - I just look at android as a hobby for fun as something different
Click to expand...
Click to collapse
You should learn programming, for pc or android, you are missing a lot of fun here