Skip to content

Commit

Permalink
TemplateWriter, GmailChat userjs writer
Browse files Browse the repository at this point in the history
  • Loading branch information
artyfarty committed Jan 24, 2012
1 parent 65c9594 commit d91bdef
Show file tree
Hide file tree
Showing 6 changed files with 345 additions and 54 deletions.
56 changes: 3 additions & 53 deletions UniversalEmoticonPackBuilder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ static void Main(string[] args)
case "wim":
builders.Add(new WIMSkin(build_dir, packinfo));
break;
case "gmail":
builders.Add(new GMailUserjs(build_dir, packinfo));
break;
}


Expand Down Expand Up @@ -111,59 +114,6 @@ static void Main(string[] args)
}
}

abstract class SmileConfig
{
protected string packRootPath;
protected string path;
protected string imagePath;

protected PackInfo pack;
protected string client;

public SmileConfig(PackInfo pack, string client, string path)
{
this.pack = pack;
this.client = client;
this.packRootPath = path + String.Format("{0}/", PathPackFullName);
}

public void CopySmiley(string orig_file, string[] equivs)
{
File.Copy(orig_file, imagePath + RenameFile(orig_file), true);
WriteEntry(RenameFile(orig_file), equivs);
}

public void Finish() {
EndFile();

using (ZipFile zip = new ZipFile())
{
zip.FlattenFoldersOnExtract = false;
zip.AddDirectory(packRootPath);
zip.Comment = pack.Description;
zip.Save(String.Format("build/{0}.zip", PathPackFullName));
}
Directory.CreateDirectory(packRootPath).Delete(true);
}

protected abstract void WriteEntry(string file, string[] equivs);
protected abstract void EndFile();
protected virtual string RenameFile(string fname)
{
return fname;
}

public string PackFullName
{
get { return String.Format("{0} for {1}", pack.FullName, client); }
}

public string PathPackFullName
{
get { return PackFullName.Replace(' ', '_').ToLower(); }
}
}

// class that stores emoticon pack info
class PackInfo {
public string name;
Expand Down
66 changes: 66 additions & 0 deletions UniversalEmoticonPackBuilder/SmileConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Ionic.Zip;
using System.Reflection;

namespace QIPSmileBuilder
{
abstract class SmileConfig
{
protected string packRootPath;
protected string path;
protected string imagePath;
protected string buildPath;

protected PackInfo pack;
protected string client;

public SmileConfig(PackInfo pack, string client, string path)
{
this.pack = pack;
this.client = client;
this.buildPath = path;
this.packRootPath = path + String.Format("{0}/", PathPackFullName);
}

public void CopySmiley(string orig_file, string[] equivs)
{
File.Copy(orig_file, imagePath + RenameFile(orig_file), true);
WriteEntry(RenameFile(orig_file), equivs);
}

public void Finish()
{
EndFile();

using (ZipFile zip = new ZipFile())
{
zip.FlattenFoldersOnExtract = false;
zip.AddDirectory(packRootPath);
zip.Comment = pack.Description;
zip.Save(String.Format("{0}{1}.zip", buildPath, PathPackFullName));
}
Directory.CreateDirectory(packRootPath).Delete(true);
}

protected abstract void WriteEntry(string file, string[] equivs);
protected abstract void EndFile();
protected virtual string RenameFile(string fname)
{
return fname;
}

public string PackFullName
{
get { return String.Format("{0} for {1}", pack.FullName, client); }
}

public string PathPackFullName
{
get { return PackFullName.Replace(' ', '_').ToLower(); }
}
}
}
62 changes: 62 additions & 0 deletions UniversalEmoticonPackBuilder/TemplateWriter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;

namespace QIPSmileBuilder
{
class TemplateWriter
{
private string outfile;
private Dictionary<string, string> replaces;
private string tpl_file;
public string data;

public TemplateWriter(string name, string outfile, PackInfo pack)
{
this.tpl_file = name;
this.outfile = outfile;

replaces = new Dictionary<string, string>
{
{"__PACKNAME__", pack.name},
{"__PACKAUTHOR__", pack.author},
{"__PACKVERSION__", pack.version}
};
}

public void AddReplacement(string key, string value) {
replaces.Add(key, value);
}

public void Write(string s) {
data += s;
}

public void WriteLine(string l)
{
Write(String.Format("{0}\n", l));
}

public void Flush() {
var tpl = new StreamReader(String.Format("{0}/templates/{1}", System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), tpl_file));
var o = new StreamWriter(outfile);
o.AutoFlush = true;

string l;
while ((l = tpl.ReadLine()) != null)
{
foreach (var kv in replaces)
l = l.Replace(kv.Key, kv.Value);
l = l.Replace("__PACKDATA__", data);
o.WriteLine(l);
}

tpl.Close();
o.Flush();
o.Close();
}
}
}
33 changes: 32 additions & 1 deletion UniversalEmoticonPackBuilder/Writers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public MirandaSmileConfig(string path, PackInfo pack)
{
this.path = packRootPath + String.Format("{0}/", PackFullName);
this.imagePath = this.path + "Animated/";
Directory.CreateDirectory(this.path);
Directory.CreateDirectory(this.imagePath);

mirandaTheme = new StreamWriter(this.path + pack.name + ".msl", false, Encoding.GetEncoding("utf-8"));
mirandaTheme.AutoFlush = true;
Expand Down Expand Up @@ -205,4 +205,35 @@ protected override void EndFile()
wimSkin.Flush();
wimSkin.Close();
}
}

class GMailUserjs : SmileConfig
{
private TemplateWriter tw;
private int counter = 0;

public GMailUserjs(string path, PackInfo pack)
: base(pack, "Gmail", path)
{
this.path = packRootPath + String.Format("{0}/", PackFullName);
this.imagePath = this.path + "emo/";

Directory.CreateDirectory(this.imagePath);

tw = new TemplateWriter("chrome.user.js", String.Format("{0}{1}.user.js", this.path, this.PathPackFullName), pack);
tw.AddReplacement("__PACKURL__", @"http://artyfarty.ru/emo/");

}

protected override void WriteEntry(string file, string[] equivs)
{
tw.WriteLine(String.Format("['{0}','{1}'],", equivs[0], file));
counter++;
}

protected override void EndFile()
{
tw.data = tw.data.Substring(0, tw.data.Length - 2);
tw.Flush();
}
}
7 changes: 7 additions & 0 deletions UniversalEmoticonPackBuilder/emoticon_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,15 @@
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SmileConfig.cs" />
<Compile Include="TemplateWriter.cs" />
<Compile Include="Writers.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="templates\chrome.user.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Loading

0 comments on commit d91bdef

Please sign in to comment.