- spiff - 2012-03-06
Heh of course that is okay, it's not like I have any saying in that. Just giving an option and a opinion.
- fmronan - 2012-03-06
Quote:i hope it´s ok to release it windows-only.
so that's not for me
- phil65 - 2012-03-07
fmronan Wrote:so that's not for me
then send me your files, I´ll convert them for you.
- phil65 - 2012-03-07
is this enough for an UTF- 8 Header?
Code: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- phil65 - 2012-03-07
Ok, here it is
http://www.gtwf-koeln.de/xmlconvertgui.exe
Please report bugs, missing tags etc...
feedback is always welcome.
current limiitations:
does net convert <posx>400r</posx> for example
no conversion of attributes (for example for animation and border tags)
seems to hang when adding a lot of files... just wait a bit
made some changes some minutes ago, i hope everything works ok.
and here´s the code
Code: Imports System.Xml
Imports System.Text
Imports System
Imports System.IO
Public Class Filechooser
Public strOutputFolder As String = ""
Public StrArray As String() = {"posx", "posy", "width", "height", "textoffsetx", "textoffsety", "radiowidth", "radioheight", "radioposx", "radioposy", "textwidth", "border"}
Public doc As New XmlDocument()
Public multiplyFactor As Double = 1.5
Public Filenames As String() = {}
Public SafeFilenames As String() = {}
Public elementlist As XmlNodeList ' must be seperate for all ??
Public TempLetter As String
Public ElementCounter As String
Private Sub Filechooser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ConversionDropDown.Items.Add("720p --> 1080p")
ConversionDropDown.Items.Add("No Change")
ConversionDropDown.SelectedIndex = 0
EncodingDropDown.Items.Add("UTF-8")
EncodingDropDown.Items.Add("ANSI")
EncodingDropDown.SelectedIndex = 0
OutputLog.AppendText("Program started" & vbCrLf)
End Sub
Private Sub ChooseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChooseButton.Click
OpenFileDialog.Title = "Choose XML file"
OpenFileDialog.Filter = "XML Files|*.xml"
Dim DidWork As Integer = OpenFileDialog.ShowDialog()
If DidWork = DialogResult.Cancel Then
Else
OutputButton.Visible = True
Filenames = OpenFileDialog.FileNames
SafeFilenames = OpenFileDialog.SafeFileNames
If Filenames.Length = 1 Then
OutputLog.AppendText("XML File chosen: " + SafeFilenames(0) & vbCrLf)
xmlname.Text = SafeFilenames(0)
Else
OutputLog.AppendText("Amount Of Files Chosen: " + Filenames.Length.ToString & vbCrLf)
For i = 0 To Filenames.Length - 1
OutputLog.AppendText(SafeFilenames(i) & vbCrLf)
Next i
xmlname.Text = Filenames.Length.ToString + " Files chosen"
End If
If strOutputFolder <> "" Then
ConvertButton.Enabled = True
End If
End If
End Sub
Sub changeElements(ByVal tag As String, ByVal counter As Integer)
OutputLog.AppendText("Changing " + tag + " values..." & vbCrLf)
elementlist = doc.GetElementsByTagName(tag)
For i = 0 To elementlist.Count - 1
Dim number As Integer
If Int32.TryParse(elementlist(i).InnerXml, number) Then
elementlist(i).InnerXml = number
OutputLog.AppendText(elementlist(i).InnerXml)
OutputLog.AppendText(" => ")
elementlist(i).InnerXml = Math.Round(elementlist(i).InnerXml * multiplyFactor)
OutputLog.AppendText(elementlist(i).InnerXml & vbCrLf)
Else
OutputLog.AppendText("Attempted conversion of " + elementlist(i).InnerXml + " failed." & vbCrLf)
If elementlist(i).InnerXml.Length > 0 Then
' TempLetter = elementlist(i).InnerXml.ToString.Substring(0, 1)
elementlist(i).InnerXml = elementlist(i).InnerXml.ToString.Substring(0, elementlist(i).InnerXml.Length - 1)
OutputLog.AppendText("Removed last letter... " & vbCrLf)
OutputLog.AppendText(elementlist(i).InnerXml & vbCrLf)
If Int32.TryParse(elementlist(i).InnerXml, number) Then
OutputLog.AppendText("success " & vbCrLf)
elementlist(i).InnerXml = Math.Round(elementlist(i).InnerXml * multiplyFactor)
OutputLog.AppendText(elementlist(i).InnerXml & vbCrLf)
End If
End If
End If
Next i
End Sub
Public Sub ConvertButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConvertButton.Click
Try
' Create an XML declaration.
Dim xmldecl As XmlDeclaration
xmldecl = doc.CreateXmlDeclaration("1.0", Nothing, Nothing)
Select Case EncodingDropDown.SelectedIndex
Case 0
xmldecl.Encoding = "UTF-8"
Case 1
xmldecl.Encoding = "ISO-8859-1"
End Select
xmldecl.Standalone = "yes"
Select Case ConversionDropDown.SelectedIndex
Case 0
multiplyFactor = 1.5
OutputLog.AppendText("converting 720 ==> 1080: Factor 1.5" & vbCrLf)
Case 1
multiplyFactor = 1
OutputLog.AppendText("only converting Encoding / adding Headers" & vbCrLf)
End Select
ElementCounter = 0
For j = 0 To Filenames.Length - 1
OutputLog.AppendText("Processing " + SafeFilenames(j) & vbCrLf)
'Create the XmlDocument.
doc.Load(Filenames(j))
If HeaderOption.Checked Then
Dim root As XmlElement = doc.DocumentElement
doc.InsertBefore(xmldecl, root)
End If
If multiplyFactor <> 1 Then
For i = 0 To StrArray.Length - 1
changeElements(StrArray(i), j)
Next i
End If
' If EncodingDropDown.SelectedIndex = 0 Then
Dim wrtr As XmlTextWriter = Nothing
Select Case EncodingDropDown.SelectedIndex
Case 0
wrtr = New XmlTextWriter(strOutputFolder + "\" + SafeFilenames(j), Encoding.UTF8)
Case 1
wrtr = New XmlTextWriter(strOutputFolder + "\" + SafeFilenames(j), Encoding.ASCII)
End Select
wrtr.Formatting = Formatting.Indented
doc.WriteTo(wrtr)
wrtr.Close()
OutputLog.AppendText(SafeFilenames(j) + " created successfully" & vbCrLf)
ElementCounter = ElementCounter + 1
Next j
Catch xmlex As XmlException ' Handle the Xml Exceptions here.
Console.WriteLine("{0}", xmlex.Message)
Catch ex As Exception ' Handle the generic Exceptions here.
Console.WriteLine("{0}", ex.Message)
End Try
OutputLog.AppendText("All Files converted" & vbCrLf)
MsgBox(ElementCounter + " XML Files converted." & vbCrLf & "Please adjust the remaining tags by hand")
ReDim Filenames(0)
ReDim SafeFilenames(0)
xmlname.Text = ""
ConvertButton.Enabled = False
End Sub
Private Sub OutputButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OutputButton.Click
Do
FolderBrowserDialog.Description = "Choose Output Folder"
Dim DidWork As Integer = FolderBrowserDialog.ShowDialog()
If DidWork = DialogResult.Cancel Then
Else
strOutputFolder = FolderBrowserDialog.SelectedPath
If Filenames(0) <> "" Then
ConvertButton.Enabled = True
End If
OutputLabel.Text = strOutputFolder + "\"
OutputLog.AppendText("Output Folder chosen:" & vbCrLf)
OutputLog.AppendText(strOutputFolder & vbCrLf)
End If
If (strOutputFolder + "\" + SafeFilenames(0) = Filenames(0)) Then
MsgBox("You´ve chosen the soure directory. please change the output path.")
End If
Loop While (strOutputFolder + "\" + SafeFilenames(0) = Filenames(0))
End Sub
End Class
If someone wants to have the project files, just ask.
- wyrm - 2012-03-07
phil65 Wrote:Ok, here it is
http://www.gtwf-koeln.de/xmlconvertgui.exe
Please report bugs, missing tags etc...
feedback is always welcome.
current limiitations:
does net convert <posx>400r</posx> for example
no conversion of attributes (for example for animation and border tags)
seems to hang when adding a lot of files... just wait a bit
made some changes some minutes ago, i hope everything works ok.
If someone wants to have the project files, just ask. phil65,
I had someone write me a perl script that did something similar, but only looked after height, width, posx and posy. Only downside I can see with what you have (other than being windows only) is that the fixed conversion factors. If you allowed the user to input them, this could be used to convert from one resolution to any other (ie 720p to iPad native).
Just a thought.
Wyrm (xTV-SAF)
- phil65 - 2012-03-07
wyrm Wrote:phil65,
I had someone write me a perl script that did something similar, but only looked after height, width, posx and posy. Only downside I can see with what you have (other than being windows only) is that the fixed conversion factors. If you allowed the user to input them, this could be used to convert from one resolution to any other (ie 720p to iPad native).
Just a thought.
Wyrm (xTV-SAF)
would take one minute to change that if someone wants it i could do that.
- Maxoo - 2012-03-07
iPad isn't 16:9, is it ?
- phil65 - 2012-03-07
Maxoo Wrote:iPad isn't 16:9, is it ?
i also think that the 16:9 skins are scaled to Retina display ratio by XBMC, so no need to adjust the skins.
EDIT: updated the .exe, should convert <posx>400r</posx> properly now (removing r --> scaling --> adding r)
- wyrm - 2012-03-08
phil65 Wrote:i also think that the 16:9 skins are scaled to Retina display ratio by XBMC, so no need to adjust the skins.
phil65,
XBMC will convert to any resolution really. Point was more that you be able to produce a skin that was coded to your target devices native res. Resulting skin would still run fine on any XBMC device, just that you could use your utility to fine tune for particular target. Touched runs just fine on most platforms, it's just targeted at the iPad.
Wyrm (xTV-SAF)
- phil65 - 2012-03-08
wyrm Wrote:phil65,
XBMC will convert to any resolution really. Point was more that you be able to produce a skin that was coded to your target devices native res. Resulting skin would still run fine on any XBMC device, just that you could use your utility to fine tune for particular target. Touched runs just fine on most platforms, it's just targeted at the iPad.
Wyrm (xTV-SAF)
so you want seperate x and y scaling? could be implemented easily, if someone really wants to use it.
- wyrm - 2012-03-08
phil65 Wrote:so you want seperate x and y scaling? could be implemented easily, if someone really wants to use it. I know it could get a work out on the constantly threatened "Slab" project of mine.
Wyrm (xTV-SAF)
- Sinnocence - 2012-03-08
I took a sample skin XML file from google for XBMC and put together a quick XSL based on the rules in the above VB source code. You may need to do a bit of work to get it perfect for you...
Matches the specified element list and for each replaces their value with the previous value * 1.5, rounded up/down as appropriate.
[edit] This didn't satsfy all values, see Post #37 for an updated copy [/edit]
Code: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indents="yes"/>
<xsl:variable name="MULTIPLIER">1.5</xsl:variable>
<!-- template (copies input file as-is) -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- specific overrides -->
<xsl:template match="posx|posy|width|height|textoffsetx|textoffsety|radiowidth|radioheight|radioposx|radioposy|textwidth|border">
<xsl:element name="{local-name()}">
<xsl:value-of select="round(number(.) * number($MULTIPLIER))"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
- spiff - 2012-03-08
nice. for linux users,
Code: for file in *xml; do xsltproc ~/foo.xslt "$file" > foo && mv foo "$file"; done
will transform all xmls in the current directory, assuming the xslt from the previous post is available as ~/foo.xslt
- phil65 - 2012-03-08
Sinnocence Wrote:I took a sample skin XML file from google for XBMC and put together a quick XSL based on the rules in the above VB source code. You may need to do a bit of work to get it perfect for you...
Matches the specified element list and for each replaces their value with the previous value * 1.5, rounded up/down as appropriate.
Code: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indents="yes"/>
<xsl:variable name="MULTIPLIER">1.5</xsl:variable>
<!-- template (copies input file as-is) -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- specific overrides -->
<xsl:template match="posx|posy|width|height|textoffsetx|textoffsety|radiowidth|radioheight|radioposx|radioposy|textwidth|border">
<xsl:element name="{local-name()}">
<xsl:value-of select="round(number(.) * number($MULTIPLIER))"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
spiff Wrote:nice. for linux users,
Code: for file in *xml; do xsltproc ~/foo.xslt "$file" > foo && mv foo "$file"; done
will transform all xmls in the current directory, assuming the xslt from the previous post is available as ~/foo.xslt
nice. will try to implement changing the attributes now.
|