-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TemplateWriter, GmailChat userjs writer
- Loading branch information
Showing
6 changed files
with
345 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.