/// <summary> /// Main Constructor for this class, pre-setting vital properties right away /// </summary> /// <param name="Name">File Name (String)</param> /// <param name="FullPath">Full Path of File (String)</param> /// <param name="Format">File Format as <see cref="FFormats"/></param> /// <param name="FTyp">Optional File Type as <see cref="FTypes"/>, Default = 'FTypes.ASCII'</param> /// <remarks></remarks> public FileListItem(string Name, string FullPath, FFormats Format, FTypes FTyp = FTypes.ASCII) { this.m_Name = Name; this.m_FullPath = FullPath; this.m_Format = Format; switch (Format) { case FFormats.us_ascii: this.m_Color = Color.Black; break; case FFormats.utf_16: this.m_Color = Color.Blue; break; case FFormats.utf_8: this.m_Color = Color.Red; break; default: this.m_Color = Color.Black; break; } this.m_Label = new System.Windows.Forms.Label(); this.m_Label.Text = this.m_Name; this.m_Label.ForeColor = this.m_Color; this.m_Label.BackColor = Color.White; this.m_FType = FTyp; MForm.Controls.Add(this.Label); //AddHandler Me.m_Label.Click, AddressOf filelistitem_click this.m_Selected = false; MForm.Controls.Add(this); ToolTipAndEvents(this, this.FullPath); ToolTipAndEvents(this.Label, this.FullPath); }
//New /// <summary> /// Default constructor without any pre-set parameters /// </summary> /// <remarks></remarks> public FileListItem() { this.m_Name = ""; this.m_FullPath = ""; this.m_Format = FFormats.us_ascii; this.m_Color = Color.Red; this.m_Label = new System.Windows.Forms.Label(); this.m_Label.Text = this.m_Name; this.m_Label.ForeColor = this.m_Color; this.m_Label.BackColor = Color.White; this.m_FType = FTypes.ASCII; //AddHandler Me.m_Label.Click, AddressOf filelistitem_click this.m_Selected = false; MForm.Controls.Add(this.Label); MForm.Controls.Add(this); ToolTipAndEvents(this, this.FullPath); ToolTipAndEvents(this.Label, this.FullPath); }
static void Main(string[] args) { oConv.ProcessedFile += evHandlerProcessedFile; oConv.InfoMsg += evHandlerInfoMsg; oConv.ErrMsg += evHandlerErrMsg; oConv.AdjustnumTotal += evHandlerAdjustnumTotal; Data.MForm = F; Data.ToolTip = TT; int iArgs = Environment.GetCommandLineArgs().Count();//My.Application.CommandLineArgs.Count(); string[] paramsT = Environment.GetCommandLineArgs(); int iVal = 0; double dVal = 0; string sVal = ""; int a = 0; int index = 0; bool bNamedParam = false; string sNamedParam = ""; string sPath = ""; bool bError = false; if (iArgs > 0) { if (!bDebug == true) { for (a = 0; a <= iArgs - 1; a++) { string sParam = paramsT[a]; Console.WriteLine(Strings.Right(" " + a.ToString(), 5) + "." + sParam); } Console.WriteLine("... End Params"); } for (a = 0; a <= iArgs - 1; a++) { bNamedParam = false; string sParam = paramsT[a]; if (Strings.Left(sParam, 1) == "/" & InStr(sParam, ":", CompareMethod.Text) > 2) { sNamedParam = Strings.Left(sParam, InStr(sParam, ":", CompareMethod.Text)); bNamedParam = true; } if (bNamedParam == true) { sVal = Strings.Right(sParam, Len(sParam) - Len(sNamedParam)); switch (LCase(sNamedParam)) { case "/ftyp:": sExtFilter = sVal; aExtFilter = Split(sVal, ","); break; case "/out:": sVal = Trim(UCase(sVal)); switch (sVal) { case "ASC": sOutPutFormat = sVal; iOutFormat = FTypes.ASCII; break; case "ANS": sOutPutFormat = sVal; break; iOutFormat = FTypes.ANSI; case "HTML": sOutPutFormat = sVal; iOutFormat = FTypes.HTML; break; case "UTF8": pUTF = "UTF8"; sOutPutFormat = "UTF"; iOutFormat = FTypes.Unicode; break; case "UTF16": pUTF = "UTF16"; sOutPutFormat = "UTF"; iOutFormat = FTypes.Unicode; break; case "PCB": sOutPutFormat = sVal; iOutFormat = FTypes.PCB; break; case "WC2": sOutPutFormat = sVal; iOutFormat = FTypes.WC2; break; case "WC3": sOutPutFormat = sVal; iOutFormat = FTypes.WC3; break; case "AVT": sOutPutFormat = sVal; iOutFormat = FTypes.AVT; break; case "VID": sOutPutFormat = sVal; iOutFormat = FTypes.VID; break; case "BIN": sOutPutFormat = sVal; iOutFormat = FTypes.Bin; break; case "IMG": sOutPutFormat = sVal; iOutFormat = FTypes.IMG; break; default: Console.Error.WriteLine("'" + sVal + "' is not a valid value for the /OUT: Format Option."); bError = true; break; } break; case "/font:": sHTMLFont = sVal; break; case "/nocol:": bNoColors = true; break; case "/small:": bSmallFont = true; break; case "/save:": sVal = Trim(sVal); try { if (Directory.Exists(sVal)) { soutPath = sVal; bOutPathInput = false; } else { Console.Error.WriteLine("'" + sVal + "' is not a valid output path or does not exist."); bError = true; } } catch (Exception ex) { Console.Error.WriteLine("'" + sVal + "' is not a valid output path or does not exist."); bError = true; } break; case "/ext:": bReplaceExt = true; txtExt = sVal; break; case "/newext:": bReplaceExt = false; txtExt = sVal; break; case "/over:": sVal = Trim(UCase(sVal)); break; switch (sVal) { case "OVER": OutputFileExists = 0; break; case "SKIP": OutputFileExists = 1; break; case "REN": OutputFileExists = 2; break; default: Console.Error.WriteLine("'" + sVal + "' is not a valid option for the /OVER: Option."); bError = true; break; } case "/thumbscale:": sVal = Trim(UCase(sVal)); switch (sVal) { case "PROP": iThumbResOpt = 0; break; case "WIDTH": iThumbResOpt = 1; break; case "HEIGHT": iThumbResOpt = 2; break; case "CUSTOM": iThumbResOpt = 3; break; } break; case "/scale:": if (IsNumeric(sVal)) { iThumbProp = Math.Abs(Convert.ToInt32(sVal)); } break; case "/width:": if (IsNumeric(sVal)) { iThumbWidth = Math.Abs(Convert.ToInt32(sVal)); } break; case "/height:": if (IsNumeric(sVal)) { iThumbHeight = Math.Abs(Convert.ToInt32(sVal)); } break; case "/cp:": if (CodePageExists(Trim(sVal))) { sCodePg = Trim(UCase(sVal)); } else { Console.Error.WriteLine("'" + sVal + "' is not a valid code page value."); bError = true; } break; case "/codec:": sCodec = sVal; break; case "/fps:": if (IsNumeric(sVal)) { pFPS = Math.Abs(Convert.ToInt32(sVal)); } break; case "/bps:": if (IsNumeric(sVal)) { pBPS = Math.Abs(Convert.ToInt32(sVal)); } break; case "/extend:": if (IsNumeric(sVal)) { pExtend = Math.Abs(System.Convert.ToInt32(sVal)); } break; } } else { switch (LCase(sParam)) { case "/?": bShowHelp = true; break; case "/h": bShowHelp = true; break; case "/help": bShowHelp = true; break; case "/cplist": bShowCPList = true; break; case "/sanitize": bSanitize = true; break; case "/anim": pAnim = "Anim"; bAnimation = true; break; case "/sauce": pSauce = "Keep"; bOutputSauce = true; break; case "/object": bHTMLComplete = false; break; case "/thumb": bThumb = true; break; default: sInputPath = sParam; break; } } } if (bThumb == true) { switch (iThumbResOpt) { case 0: if (iThumbProp == 0) { Console.Error.WriteLine("/SCALE parameter not provided for proportional thumbnail scaling."); bError = true; } break; case 1: if (iThumbWidth == 0) { Console.Error.WriteLine("/WIDTH parameter not provided for proportional fixed width thumbnail scaling."); bError = true; } break; case 2: if (iThumbHeight == 0) { Console.Error.WriteLine("/HEIGHT parameter not provided for proportional fixed height thumbnail scaling."); bError = true; } break; case 3: if (iThumbWidth == 0 | iThumbHeight == 0) { Console.Error.WriteLine("/WIDTH and/or /HEIGHT parameter(s) not provided for custom size thumbnail scaling."); bError = true; } break; } } if (bShowHelp == true) { HelpMessage(); System.Environment.Exit(0); } if (bShowCPList == true) { BuildCPList(); System.Environment.Exit(0); } if (sInputPath == "") { Console.Error.WriteLine("Input File/Folder Path are missing."); bError = true; } else { try { if (Directory.Exists(sInputPath)) { bInputFile = false; BuildFileList(sInputPath); if (Data.ListInputFiles.Count() == 0) { Console.Error.WriteLine("Input Folder: '" + sInputPath + "' no files to process found."); bError = true; } else { Console.WriteLine("# Files to Process: " + Data.ListInputFiles.Count + ", Break down by Type: "); string sTmp = ""; for (int b = 0; b <= 5; b++) { if (aFTCounts[b] != 0) { switch (b) { case 0: sTmp += ", ASC: "; break; case 1: sTmp += ", ANS: "; break; case 2: sTmp += ", HTM: "; break; case 3: sTmp += ", UTF: "; break; case 4: sTmp += ", PCB: "; break; case 5: sTmp += ", BIN: "; break; case 6: sTmp += ", WC2: "; break; case 7: sTmp += ", WC3: "; break; case 8: sTmp += ", AVT: "; break; } sTmp += aFTCounts[b].ToString(); } } if (sTmp != "") { sTmp = Strings.Right(sTmp, sTmp.Length - 2); } Console.WriteLine(sTmp); Console.WriteLine(""); } } else { if (File.Exists(sInputPath)) { bInputFile = true; try { AddFile(sInputPath); } catch (Exception ex) { } if (Data.ListInputFiles.Count == 0) { Console.Error.WriteLine("Input File: '" + sInputPath + "' cannot be processed. Unknow/Unsupported File Type or not accessible."); bError = true; } } else { Console.Error.WriteLine("Input File/Folder Path: '" + sInputPath + "' does not exist."); bError = true; } } } catch (Exception ex) { Console.Error.WriteLine("Invalid Input File/Folder Path Value: '" + sInputPath + "'."); bError = true; } } if (sOutPutFormat == "") { Console.Error.WriteLine("Output Format was not specified."); bError = true; } if (bError == true) { Console.Error.WriteLine("Start with /h option for Help."); System.Environment.Exit(0); } if (txtExt == "") { switch (sOutPutFormat) { case "HTML": if (bHTMLComplete == false) { txtExt = "WEB"; } else { txtExt = "HTM"; } break; case "UTF": txtExt = "TXT"; break; case "IMG": txtExt = "PNG"; break; case "VID": txtExt = "AVI"; break; default: txtExt = sOutPutFormat; break; } } string sStr = ""; iNumProc = Data.ListInputFiles.Count; Console.WriteLine("Output Format: " + sOutPutFormat); switch (sOutPutFormat) { case "HTML": sStr = "Sanitize: "; if (bSanitize) { sStr += "YES"; } else { sStr += "NO"; } sStr += ", Full HTML: "; if (bHTMLComplete) { sStr += "YES"; } else { sStr += "NO"; } sStr += ", Anim: "; if (bAnimation) { sStr += "YES"; } else { sStr += "NO"; } Console.WriteLine(sStr); Console.WriteLine("Font: " + sHTMLFont); break; case "UTF": sStr = "Unicode Format: " + pUTF; Console.WriteLine(sStr); break; case "IMG": sStr = "No Colors?: " + bNoColors.ToString(); sStr += ", Small Font: " + bSmallFont.ToString() + "\r\n"; Console.WriteLine(sStr); if (bThumb) { sStr = "Create Thumbnails."; switch (iThumbResOpt) { case 0: sStr += " Scale to: " + iThumbProp + "% of org image size."; break; case 1: sStr += " Fixed width: " + iThumbWidth + " pixels."; break; case 2: sStr += " Fixed Height: " + iThumbHeight + " pixels."; break; case 3: sStr += " Custom Size: " + iThumbWidth + "x" + iThumbHeight + " pixels."; break; } Console.WriteLine(sStr); } break; case "VID": sStr = "FPS: " + pFPS.ToString() + ", BPS: " + pBPS.ToString(); if (UCase(txtExt) == "AVI" | UCase(txtExt) == "MPG") { sStr += ", Codec: " + sCodec; } Console.WriteLine(sStr); sStr = "Extend Last Frame by " + pExtend + " seconds."; Console.WriteLine(sStr); break; } sStr = "Output Path: "; if (bOutPathInput) { sStr += " as input"; } else { sStr += soutPath; } Console.WriteLine(sStr); sStr = "Extension: " + txtExt; if (bReplaceExt) { sStr += " (Replace)"; } else { sStr += " (Add)"; } Console.WriteLine(sStr); sStr = "Keep Sauce Meta: "; if (bOutputSauce) { sStr += "YES"; } else { sStr += "NO"; } Console.WriteLine("CodePage: " + sCodePg); Console.WriteLine(sStr); Console.WriteLine("----------------------------------------------------------"); Data.txtExt = txtExt; Data.rOutPathInput = bOutPathInput; Data.rReplaceExt = bReplaceExt; Data.outPath = soutPath; Data.bForceOverwrite = bForceOverwrite; Data.sHTMLFont = sHTMLFont; Data.pOutExist = OutputFileExists; Data.bCreateThumbs = bThumb; Data.iThumbsResOpt = iThumbResOpt; Data.iThumbsScale = iThumbProp; Data.iThumbsWidth = iThumbWidth; Data.iThumbsHeight = iThumbHeight; Data.sOutPutFormat = sOutPutFormat; Data.pOut = sOutPutFormat; //sInputFormat = MainForm.pIn.Tag.ToString Data.bOutputSauce = bOutputSauce; Data.pAnim = pAnim; Data.pSauce = pSauce; Data.bAnimation = bAnimation; Data.bRemoveCompleted = true; Data.bSanitize = bSanitize; Data.pSanitize = bSanitize; Data.pCP = sCodePg; Data.sCodePg = sCodePg; Data.pNoColors = bNoColors; Data.pSmallFont = bSmallFont; Data.pHTMLEncode = bHTMLEncode; Data.pHTMLComplete = bHTMLComplete; Data.selUTF = pUTF; Data.BPS = pBPS; Data.FPS = pFPS; Data.LastFrame = pExtend; if (sOutPutFormat == "VID") { switch (UCase(txtExt)) { case "AVI": Data.VidCodec = sCodec; break; case "MPG": Data.VidCodec = sCodec; break; default: Data.VidCodec = ""; break; } } oConv.ConvertAllFiles(); Console.WriteLine("DONE PROCESSING!"); Console.WriteLine("... bye See you next time. Roy/SAC."); } else { HelpMessage(); } }
public static FTypes DetermineFileType(string sFile) { FTypes sRes = FTypes.ASCII; byte[] eBte; string sData = ""; FileStream ofile; if (File.Exists(sFile)) { if (GetFileSizeNum(sFile) > 0) { ofile = File.Open(sFile, FileMode.Open, FileAccess.Read); int iSize = System.Convert.ToInt32(ofile.Length - 1); if (iSize > 10000) { iSize = 10000; } // ERROR: Not supported in C#: ReDimStatement eBte = new byte[iSize]; ofile.Seek(0, SeekOrigin.Begin); ofile.Read(eBte, 0, iSize + 1); ofile.Close(); sData = ConverterSupport.Convert.ByteArrayToString(eBte); } } if (sData != "" & !(sData == null)) { if (InStr(1, sData, Strings.Chr(27) + "[", CompareMethod.Text) > 0) { if (InStr(1, sData, Strings.Chr(27) + "[0;0;40m", CompareMethod.Text) > 0) { sRes = FTypes.WC2; } else { sRes = FTypes.ANSI; } } else { if (InStr(1, sData, "<div", CompareMethod.Text) > 0 | InStr(1, sData, "<", CompareMethod.Text) > 0 | InStr(1, sData, " ", CompareMethod.Text) > 0 | InStr(1, sData, ";&#", CompareMethod.Text) > 0) { sRes = FTypes.HTML; } else { if (ConverterSupport.Convert.RegExTest(sData, "@X[0-9A-F]{2}", RegexOptions.Singleline) == true) { sRes = FTypes.PCB; } else { if (ConverterSupport.Convert.RegExTest(sData, "@[0-9A-F]{2}@", RegexOptions.Singleline) == true) { sRes = FTypes.WC3; } else { if (InStr(1, sData, Chr(22).ToString() + Chr(1).ToString(), CompareMethod.Binary) > 0) { sRes = FTypes.AVT; } else { if (InStr(1, sData, Chr(7).ToString(), CompareMethod.Binary) > 0) { sRes = FTypes.Bin; } else { sRes = FTypes.ASCII; } } } } } } } return(sRes); }
private void ChangeState(FTypes ftype) { _state.Location = Location; _state.Type = ftype; }
//============================================================ // <T>构造资源压缩文件。</T> // // @param compressCd 压缩类型 // @param data 数据 // @param blockSize 分块大小 //============================================================ public FRsCompressFile(string compressCd, FTypes <byte> data, int blockSize = 0) { _compressCd = compressCd; Assign(data); _blockSize = blockSize; }