Quiero adaptar este código a otro

(1/1)

Meta:
Buenas:

Teniendo un código de Python 2.x, quiero adaptarlo a la consola C# si es posible. Si no, pues con Windows Form.
Ya no recuerdo casi nada de Python y quiero tenerlo en C#.

El código del Pyhon es este.
Código
import os, sys, tkFileDialog,Tkinter
 
root = Tkinter.Tk()
root.withdraw()
 
formats = [ ('Roms Super Nintendo SMC','.smc'),('Roms Super Nintendo SFC','.sfc'),('Fichier Bin','.bin'),('Roms Super Nintendo','.smc .sfc .bin') ]
 
input = tkFileDialog.askopenfile(parent=root,mode='rb',filetypes=formats,
                                title='Seleccione el archivo para intercambiar bin HI a LO como A16->A15, A17->A16...A21->A20 y A15->21')
if not input:
   print "Error: no se puede abrir el archivo."
   sys.exit()
 
output = tkFileDialog.asksaveasfile(parent=root,mode='wb',filetypes=formats,title='Crear nombre de archivo de salida.')
if not output:
   print "Error: no se puede crear el archivo de salida."
   sys.exit()
 
 
   # reading input file to a byte array
   data = bytearray(input.read())
 
   # calculating rom size in 2 exponants
   expsize = 0
   bytesize = len(data)
   while bytesize > 1:
           expsize += 1
           bytesize = bytesize // 2
 
   # init a proper size empty bytearray
   buffer = bytearray()
   for i in range(2**expsize): buffer.append(0)
 
   # let's do the swap
   count = 0
   for i in range(len(data)):
           addr = (i & 0x7fff) + ((i & 0x008000) << (expsize - 16)) + ((i & 0x010000) >> 1) + ((i & 0x020000) >> 1) + ((i & 0x040000) >> 1)
           + ((i & 0x080000) >> 1) + ((i & 0x100000) >> 1) + ((i & 0x200000) >> 1)
           if addr != i: count += 1
           buffer[addr] = data[i]
   print "Intercambiadas %s (%s) direcciones" % (count, hex(count))
 
   # writing output file
   output.write(buffer)
 
   # close file handles
   input.close()
   output.close()

Es cierto que con Visual Studio Community 2019 me ejecuta bien el Python, pero dependo de compilador y con C# no.

Esto parece una tarea muy complicada.

Muchas gracias.

Navegación

[0] Índice de Mensajes