⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umd_genegine.cs

📁 用VC.NET开发的应用于Symbian上的电子书开发源代码.
💻 CS
📖 第 1 页 / 共 3 页
字号:
using System;
using System.Windows.Forms;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Text;
using ICSharpCode.SharpZipLib.Zip.Compression;

namespace mBookMaker
{
	/// <summary>
	/// UMD_GENEGINE 的摘要说明。
	/// </summary>
	public class UMD_GENEGINE
	{
		// Fields
		private const int A_32K_BYTE = 0x8000;
		private byte ACTUAL_WIDTH_S60_HORI;
		private byte ACTUAL_WIDTH_S60_VERT;
		private byte ACTUAL_WIDTH_SP;
		private const uint BASE_REFN_CHAP_OFF = 0x3000;
		private const uint BASE_REFN_CHAP_STR = 0x4000;
		private const uint BASE_REFN_CONTENT = 0x2000;
		private const uint BASE_REFN_COVER = 0x1000;
		private const uint BASE_REFN_PAGE_OFFSET = 0x7000;
		private const string BEYOND_END_FLAG = "\0";
		private const int BYTE_LEN = 1;
		private const byte COVER_TYPE_BMP = 0;
		private const byte COVER_TYPE_GIF = 2;
		private const byte COVER_TYPE_JPG = 1;
		private const int CURR_VERSION = 1;
		private const short DCTS_CMD_ID_AUTHOR = 3;
		private const short DCTS_CMD_ID_CDS_KEY = 240;
		private const short DCTS_CMD_ID_CHAP_OFF = 0x83;
		private const short DCTS_CMD_ID_CHAP_STR = 0x84;
		private const short DCTS_CMD_ID_CONTENT_ID = 10;
		private const short DCTS_CMD_ID_COVER_PAGE = 130;
		private const short DCTS_CMD_ID_DAY = 6;
		private const short DCTS_CMD_ID_FILE_LENGTH = 11;
		private const short DCTS_CMD_ID_FIXED_LEN = 12;
		private const short DCTS_CMD_ID_GENDER = 7;
		private const short DCTS_CMD_ID_LICENSE_KEY = 0xf1;
		private const short DCTS_CMD_ID_MONTH = 5;
		private const short DCTS_CMD_ID_PAGE_OFFSET = 0x87;
		private const short DCTS_CMD_ID_PUBLISHER = 8;
		private const short DCTS_CMD_ID_REF_CONTENT = 0x81;
		private const short DCTS_CMD_ID_TITLE = 2;
		private const short DCTS_CMD_ID_VENDOR = 9;
		private const short DCTS_CMD_ID_VERSION = 1;
		private const short DCTS_CMD_ID_YEAR = 4;
		private const byte FIXED_LINE_PER_PAGE_S60 = 50;
		private const byte FIXED_LINE_PER_PAGE_SP = 0x19;
		private string iAuthor;
		private byte[] ibContent;
		private int[] iChapOff;
		private ArrayList iChapStr;
		private ArrayList iChapter;
		private int iCID;
		private string iContent;
		private string iCoverFile;
		private string iDay;
		private string iGender;
		private string iMonth;
		private const int INT_LEN = 4;
		private short iPGKSeed;
		private string iPublisher;
		private string iSaveTo;
		private string iTitle;
		private int iTotalen;
		private string iVendor;
		private ArrayList iWidthData_S60;
		private ArrayList iWidthData_SP;
		private string iYear;
		private byte[][] iZippedSeg;
		private const string KEY_CODE_TAB = "\t";
		private const byte S60_FONT_SIZE_BIG = 0x10;
		private const byte S60_FONT_SIZE_SMALL = 12;
		private const byte SEREIS60_FONTS_COUNT = 2;
		private const int SHORT_LEN = 2;
		private const byte SP_FONT_SIZE_10 = 10;
		private const byte SP_FONT_SIZE_MAX = 0x10;
		private const byte SP_FONT_SIZE_MIN = 6;
		private const string SYMBIAN_RETURN = "\u2029";
		private const string SYMBIAN_SPACE = "\u3000";
		private const byte UMD_DCTD_HEAD_LEN = 9;
		private const byte UMD_DCTS_HEAD_LEN = 5;
		private const int UMD_FREE_CID_MIN = 100000000;
		private const int UMD_FREE_PGK_SEED_MIN = 0x400;
		private const int UMD_LICENSEKEY_LEN = 0x10;
		private const int UMD_MAX_BOOKMARK_STR_LEN = 40;
		private const byte UMD_PLATFORM_ID_NONE = 0;
		private const byte UMD_PLATFORM_ID_S60 = 1;
		private const byte UMD_PLATFORM_ID_SP = 5;
		private const int UMD_SEGMENT_LENGTH = 0x8000;
		private const byte VER_PKG_LEN = 3;
		private const string WINDOWS_RETURN = "\r\n";
		private const int ZIP_LEVEL = 9;

		//漫画书使用
		private ArrayList MHiChapterOff;// = new ArrayList();//目录偏移
		private ArrayList MHsChapterStr;// = new ArrayList();//目录名称
		private ArrayList MHsChapterJpg;// = new ArrayList();//图片列表

		// Nested Types
		[StructLayout(LayoutKind.Sequential)]
			private struct SWidthData
		{
			public byte FontSize;
			public ushort rngFrom;
			public ushort rngTo;
			public uint vCount;
			public byte[] Value;
		}
		// Methods
		public UMD_GENEGINE()
		{
			this.iPGKSeed = 0;
			this.iChapter = new ArrayList();
			this.iChapStr = new ArrayList();
			this.iWidthData_SP = new ArrayList();
			this.iWidthData_S60 = new ArrayList();
			this.ACTUAL_WIDTH_SP = 0xa6;
			this.ACTUAL_WIDTH_S60_VERT = 0xac;
			this.ACTUAL_WIDTH_S60_HORI = 0xcc;
			this.MHiChapterOff = new ArrayList();//目录偏移
			this.MHsChapterStr = new ArrayList();//目录名称
			this.MHsChapterJpg = new ArrayList();//图片列表

		}
		private byte CharWidth_S60(string Char, byte pFontSize)
		{
			ushort num1 = Char[0];
			for (int num2 = 0; num2 < this.iWidthData_S60.Count; num2++)
			{
				UMD_GENEGINE.SWidthData data1 = (UMD_GENEGINE.SWidthData) this.iWidthData_S60[num2];
				if (((data1.FontSize == pFontSize) && (num1 >= data1.rngFrom)) && (num1 <= data1.rngTo))
				{
					if (data1.vCount == 1)
					{
						return data1.Value[0];
					}
					return data1.Value[num1 - data1.rngFrom];
				}
			}
			return pFontSize;
		}
		private byte CharWidth_SP(string Char, byte pFontSize)
		{
			ushort num1 = Char[0];
			for (int num2 = 0; num2 < this.iWidthData_SP.Count; num2++)
			{
				UMD_GENEGINE.SWidthData data1 = (UMD_GENEGINE.SWidthData) this.iWidthData_SP[num2];
				if (((data1.FontSize == pFontSize) && (num1 >= data1.rngFrom)) && (num1 <= data1.rngTo))
				{
					if (data1.vCount == 1)
					{
						return data1.Value[0];
					}
					return data1.Value[num1 - data1.rngFrom];
				}
			}
			return pFontSize;
		}
		private bool GetPageOffsetS60(byte size, uint actual_width, ref ProgressBar pbar, out uint[] result)
		{
			ArrayList list1 = new ArrayList();
			if ((size != 0x10) && (size != 12))
			{
				result = new uint[0];
				return false;
			}
			this.GetWidthData_S60();
			list1.Add((uint)0);
			int num1 = pbar.Value;
			while (((uint) list1[list1.Count - 1]) < this.iContent.Length)
			{
				this.ParseOnePage((uint) (list1.Count - 1), size, actual_width, ref list1, 1);
				pbar.Value = num1 + ((int) ((uint) list1[list1.Count - 1]));
			}
			result = new uint[list1.Count];
			for (int num2 = 0; num2 < list1.Count; num2++)
			{
				result[num2] = ((uint) list1[num2]) * 2;
			}
			return true;
		}
		private bool GetPageOffsetSP(byte size, uint actual_width, ref ProgressBar pbar, out uint[] result)
		{
			ArrayList list1 = new ArrayList();
			if ((size < 6) || (size > 0x10))
			{
				result = new uint[0];
				return false;
			}
			this.GetWidthData_SP();
			list1.Add((uint)0);
			int num1 = pbar.Value;
			while (((uint) list1[list1.Count - 1]) < this.iContent.Length)
			{
				this.ParseOnePage((uint) (list1.Count - 1), size, actual_width, ref list1, 5);
				if ((num1 + ((int) ((uint) list1[list1.Count - 1]))) < pbar.Maximum)
				{
					pbar.Value = num1 + ((int) ((uint) list1[list1.Count - 1]));
				}
			}
			result = new uint[list1.Count];
			for (int num2 = 0; num2 < list1.Count; num2++)
			{
				result[num2] = (uint) list1[num2];
			}
			return true;
		}
		private void GetWidthData_S60()
		{
			this.iWidthData_S60.Clear();
			for (int num1 = 0; num1 < 2; num1++)
			{
				string text1 = "";
				if (num1 == 0)
				{
					text1 = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Remove(0, 8)) + @"\FontWidthData\S60CHS.S16.wdt";
				}
				if (num1 == 1)
				{
					text1 = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Remove(0, 8)) + @"\FontWidthData\S60CHS.S12.wdt";
				}
				if (File.Exists(text1))
				{
					FileStream stream1 = new FileStream(text1, FileMode.Open, FileAccess.Read);
					BinaryReader reader1 = new BinaryReader(stream1);
					while (reader1.BaseStream.Position < reader1.BaseStream.Length)
					{
						UMD_GENEGINE.SWidthData data1;
						ushort num2 = reader1.ReadUInt16();
						ushort num3 = reader1.ReadUInt16();
						uint num4 = reader1.ReadUInt16();
						byte[] buffer1 = new byte[num4];
						for (uint num5 = 0; num5 < num4; num5 += 1)
						{
							buffer1[(int) ((IntPtr) num5)] = reader1.ReadByte();
						}
						data1 = new UMD_GENEGINE.SWidthData();
						if (num1 == 0)
						{
							data1.FontSize = 0x10;
						}
						if (num1 == 1)
						{
							data1.FontSize = 12;
						}
						data1.rngFrom = num2;
						data1.rngTo = num3;
						data1.vCount = num4;
						data1.Value = buffer1;
						this.iWidthData_S60.Add(data1);
					}
					reader1.Close();
					stream1.Close();
				}
			}
		}
		private void GetWidthData_SP()
		{
			this.iWidthData_SP.Clear();
			for (int num1 = 0x10; num1 < 0x11; num1++)
			{
				string text1 = Assembly.GetExecutingAssembly().CodeBase.Remove(0, 8) + @"\FontWidthData\sunfon.s";
				string text2 = text1 + num1.ToString() + ".wdt";
				if (File.Exists(text2))
				{
					FileStream stream1 = new FileStream(text2, FileMode.Open, FileAccess.Read);
					BinaryReader reader1 = new BinaryReader(stream1);
					while (reader1.BaseStream.Position < reader1.BaseStream.Length)
					{
						UMD_GENEGINE.SWidthData data1;
						ushort num2 = reader1.ReadUInt16();
						ushort num3 = reader1.ReadUInt16();
						uint num4 = reader1.ReadUInt16();
						byte[] buffer1 = new byte[num4];
						for (uint num5 = 0; num5 < num4; num5 += 1)
						{
							buffer1[(int) ((IntPtr) num5)] = reader1.ReadByte();
						}
						data1 = new UMD_GENEGINE.SWidthData();
						data1.FontSize = (byte) num1;
						data1.rngFrom = num2;
						data1.rngTo = num3;
						data1.vCount = num4;
						data1.Value = buffer1;
						this.iWidthData_SP.Add(data1);
					}
					reader1.Close();
					stream1.Close();
				}
			}
		}
		public bool Initialize(string aTitle, string aAuthor, string aYear, string aMonth, string aDay, 
			string aGender, string aPublisher, string aVendor, string aCoverFile, int aContentID, 
			string aSaveTo, ref ArrayList aChapter, ref ArrayList aChapStr, out string aResult)
		{
			aResult = "true";
			if (aTitle.Length <= 0)
			{
				aResult = "标题不能为空";
				return false;
			}
			if (aAuthor.Length <= 0)
			{
				aResult = "作者不能为空";
				return false;
			}
			if (((aYear.Length > 4) || (aMonth.Length > 2)) || (aDay.Length > 2))
			{
				aResult = "日期非法";
				return false;
			}
			if (aChapter.Count <= 0)
			{
				aResult = "内容数量不能小于0";
				return false;
			}
			if (aChapter.Count != aChapStr.Count)
			{
				aResult = "章节标题数量和章节内容数量不符";
				return false;
			}
			if (!Directory.Exists(aSaveTo))
			{
				aResult = "保存文件的路径不存在";
				return false;
			}
			this.iTitle = aTitle;
			this.iAuthor = aAuthor;
			this.iYear = aYear;
			this.iMonth = aMonth;
			this.iDay = aDay;
			this.iGender = aGender;
			this.iPublisher = aPublisher;
			this.iVendor = aVendor;
			this.iCID = aContentID;
			this.iCoverFile = aCoverFile;
			this.iSaveTo = aSaveTo;
			if(File.Exists(this.iSaveTo + @"\" + this.iTitle + ".jpg"))
				File.Delete(this.iSaveTo + @"\" + this.iTitle + ".jpg");
			File.Copy(this.iCoverFile + ".tmp", this.iSaveTo + @"\" + this.iTitle + ".jpg");
			for (int num1 = 0; num1 < aChapter.Count; num1++)
			{
				this.iChapter.Add(((string) aChapter[num1]) + "\u2029");
				this.iChapStr.Add((string) aChapStr[num1]);
			}
			this.iChapOff = new int[this.iChapter.Count];
			return true;
		}
		public bool MHInitialize(string aTitle, string aAuthor, string aYear, string aMonth, string aDay, 
			string aGender, string aPublisher, string aVendor, string aCoverFile, int aContentID, string aSaveTo, 
			ref ArrayList iChapterOff, ref ArrayList sChapterStr, ref ArrayList sChapterJpg, 
			out string aResult)
		{
			aResult = "true";
			if (sChapterJpg.Count<=0)
			{
				aResult = "图片文件个数不能为0";
				return false;
			}
			if (aTitle.Length <= 0)
			{
				aResult = "标题不能为空";
				return false;
			}
			if (aAuthor.Length <= 0)
			{
				aResult = "作者不能为空";
				return false;
			}
			if (((aYear.Length > 4) || (aMonth.Length > 2)) || (aDay.Length > 2))
			{
				aResult = "日期非法";
				return false;
			}
			if (sChapterJpg.Count <= 0)
			{
				aResult = "内容数量不能小于0";
				return false;
			}
			if (iChapterOff.Count != sChapterStr.Count)
			{
				aResult = "章节标题数量和章节偏移数量不符";//我想不会运行到这里来
				return false;
			}
			if (!Directory.Exists(aSaveTo))
			{
				aResult = "保存文件的路径不存在";
				return false;
			}
			this.iTitle = aTitle;
			this.iAuthor = aAuthor;
			this.iYear = aYear;
			this.iMonth = aMonth;
			this.iDay = aDay;
			this.iGender = aGender;
			this.iPublisher = aPublisher;
			this.iVendor = aVendor;
			this.iCID = aContentID;
			this.iCoverFile = aCoverFile;
			this.iSaveTo = aSaveTo;
			if(File.Exists(this.iSaveTo + @"\" + this.iTitle + ".jpg"))
				File.Delete(this.iSaveTo + @"\" + this.iTitle + ".jpg");
			File.Copy(this.iCoverFile + ".tmp", this.iSaveTo + @"\" + this.iTitle + ".jpg");
			for (int num1 = 0; num1 < iChapterOff.Count; num1++)
			{
				this.MHiChapterOff.Add(iChapterOff[num1]);
				this.MHsChapterStr.Add(sChapterStr[num1]);
			}
			for (int num1 = 0; num1 < sChapterJpg.Count; num1++)
			{
				this.MHsChapterJpg.Add(sChapterJpg[num1]);
			}
			return true;
		}
		public bool LHHMake(ref ProgressBar pbar, out string result)
		{
			Random random1 = new Random();
			uint num1 = 0;
			if (this.iSaveTo.EndsWith(@"\"))
			{
				this.iSaveTo.Remove(this.iSaveTo.Length - 1, 1);
			}
			string text1 = this.iSaveTo + @"\" + this.iTitle + ".umd";
			if (File.Exists(text1))
			{
				if (MessageBox.Show("您要保存的文件已经存在,是否覆盖?", "mBook制作工具 版本:1.0", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -