Skip to content

Instantly share code, notes, and snippets.

@Rogach
Created June 19, 2012 14:24
Show Gist options
  • Save Rogach/2954487 to your computer and use it in GitHub Desktop.
Save Rogach/2954487 to your computer and use it in GitHub Desktop.
java applet file assoc
assoc .svg=SvgGraphicsFile
ftype SvgGraphicsFile=C:\Program Files\Internet Explorer\iexplore.exe "www.someplace.ru/index.html?file=" "%1"
// first, in our Applet class, we get the url, from which app was launched
val docBase = getDocumentBase()
// then, we parse it
object Loader {
def load(documentBase: String): Boolean = {
val pattern = "file="
val i = documentBase.indexOf(pattern)
if (i > 0) {
val f = decode(documentBase.drop(i + pattern.size).stripPrefix("\"%20\""))
println("loading file: %s" format f)
// load your file
true
} else false
}
def decode(l: String): String = {
var a = l.getBytes
var i = a.indexOf(37)
while (i != -1) {
val x = List(a(i+1).toChar,a(i+2).toChar).mkString
val p = List(int2ubyte(java.lang.Integer.parseInt(x,16)))
a = patch(a, i, p, 3)
i = a.indexOf(37)
}
new String(a)
}
/** Because default Seq's patch method hangs Proguard. And I do not know why. */
def patch[A : Manifest](s:Array[A], from: Int, patch: Seq[A], replaced: Int): Array[A] = {
(s.take(from) ++ patch ++ s.drop(from + replaced)).toArray
}
def int2ubyte(i:Int) = if (i > 127) (i - 256).toByte else i.toByte
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment