Skip to content

Instantly share code, notes, and snippets.

@youz
Created February 16, 2009 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youz/64983 to your computer and use it in GitHub Desktop.
Save youz/64983 to your computer and use it in GitHub Desktop.
convert filelist to X-Finder toolfolder.ini format
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
namespace list2xf
{
class list2xf
{
private const string usageText = "Usage: list2xf [-i filelist.txt] [-o output.ini] [-t typenum]";
private static Dictionary<string, string> GetOpts(string[] args)
{
var opt = new Dictionary<string, string>();
opt.Add("in", null);
opt.Add("out", null);
opt.Add("type", "1");
if ((args.Length == 0 && Console.In.Peek() < 0) || args.Length % 2 == 1)
return null;
else
{
for (int i = 0; i < args.Length; ++i )
{
switch (args[i])
{
case "-i":
opt["in"] = args[++i];
break;
case "-o":
opt["out"] = args[++i];
break;
case "-t":
opt["type"] = args[++i];
break;
default:
return null;
}
}
return opt;
}
}
public static int Main(string[] args)
{
var opt = GetOpts(args);
if (opt == null)
{
Console.WriteLine(usageText);
return 1;
}
string line;
var entries = new List<string>();
var enc = Encoding.GetEncoding("shift_jis");
try
{
using (TextReader reader = (opt["in"] == null) ? Console.In : new StreamReader(opt["in"], enc))
while ((line = reader.ReadLine()) != null)
entries.Add(line);
using (TextWriter writer = (opt["out"] == null) ? Console.Out : new StreamWriter(opt["out"], false, enc))
{
writer.WriteLine("[X-Finder]\r\nCount={0}", entries.Count);
for (int i = 0; i < entries.Count; ++i)
writer.WriteLine("Name{0}={1}\r\nPath{0}=\"{2}\"\r\nType{0}={3}\r\nIcon{0}=\r\nExt{0}=",
i, Path.GetFileName(entries[i]), entries[i], opt["type"]);
}
Console.Error.WriteLine("{0} -> {1}: {2} lines processed.",
opt["in"] == null ? "<stdin>" : opt["in"],
opt["out"] == null ? "<stdout>" : opt["out"],
entries.Count);
return 0;
}
catch (Exception e)
{
Console.Error.WriteLine(e.Message+"\r\n"+usageText);
return 1;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment