Exemplo n.º 1
0
 internal PDF417(bool compact)
 {
     this.compact = compact;
     compaction   = Compaction.AUTO;
     minCols      = 2;
     maxCols      = 30;
     maxRows      = 30;
     minRows      = 2;
 }
Exemplo n.º 2
0
 internal PDF417(bool compact)
 {
     this.compact = compact;
     compaction   = Compaction.AUTO;
     encoding     = PDF417HighLevelEncoder.DEFAULT_ENCODING;
     disableEci   = false;
     minCols      = 2;
     maxCols      = 30;
     maxRows      = 30;
     minRows      = 2;
 }
Exemplo n.º 3
0
 internal PDF417(bool compact)
 {
     this.compact = compact;
     compaction   = Compaction.AUTO;
     encoding     = null; // use default
     disableEci   = false;
     minCols      = 2;
     maxCols      = 30;
     maxRows      = 30;
     minRows      = 2;
 }
        public static PDF417.Internal.Compaction ToZXing(this Compaction other)
        {
            switch (other)
            {
            case Compaction.BYTE:
                return(PDF417.Internal.Compaction.BYTE);

            case Compaction.NUMERIC:
                return(PDF417.Internal.Compaction.NUMERIC);

            case Compaction.TEXT:
                return(PDF417.Internal.Compaction.TEXT);

            case Compaction.AUTO:
            default:
                return(PDF417.Internal.Compaction.AUTO);
            }
        }
Exemplo n.º 5
0
        public BitMatrix encode(String contents,
                                BarcodeFormat format,
                                bool compact,
                                int width,
                                int height,
                                int minCols,
                                int maxCols,
                                int minRows,
                                int maxRows,
                                Compaction compaction)
        {
            IDictionary hints = new Hashtable();

            hints[EncodeHintType.PDF417_COMPACT]    = compact;
            hints[EncodeHintType.PDF417_COMPACTION] = compaction;
            hints[EncodeHintType.PDF417_DIMENSIONS] = new Dimensions(minCols, maxCols, minRows, maxRows);
            return(encode(contents, format, width, height, hints));
        }
Exemplo n.º 6
0
        internal static void DownloadArchiver()
        {
            var notifyBox = new NotifyBox();

            notifyBox.Show(Language.GetText(nameof(en_US.InitRequirementsNotify)), Resources.GlobalTitle, NotifyBoxStartPosition.Center);
            var mirrors = NetEx.InternalDownloadMirrors;
            var verMap  = new Dictionary <string, string>();

            foreach (var mirror in mirrors)
            {
                try
                {
                    var url = PathEx.AltCombine(mirror, ".redists", "Extra", "Last.ini");
                    if (!NetEx.FileIsAvailable(url, 30000))
                    {
                        throw new PathNotFoundException(url);
                    }
                    var data = WebTransfer.DownloadString(url);
                    if (string.IsNullOrWhiteSpace(data))
                    {
                        throw new ArgumentNullException(nameof(data));
                    }
                    const string name = "7z";
                    if (string.IsNullOrEmpty(name))
                    {
                        continue;
                    }
                    var version = Ini.ReadOnly(name, "Version", data);
                    if (string.IsNullOrWhiteSpace(version))
                    {
                        continue;
                    }
                    verMap.Add(name, version);
                }
                catch (Exception ex) when(ex.IsCaught())
                {
                    Log.Write(ex);
                }
                if (verMap.Count > 0)
                {
                    break;
                }
            }
            foreach (var map in verMap)
            {
                var file = $"{map.Value}.zip";
                var path = PathEx.Combine(CachePaths.UpdateDir, file);
                foreach (var mirror in mirrors)
                {
                    try
                    {
                        var url = PathEx.AltCombine(mirror, ".redists", "Extra", map.Key, file);
                        if (!NetEx.FileIsAvailable(url, 30000))
                        {
                            throw new PathNotFoundException(url);
                        }
                        WebTransfer.DownloadFile(url, path);
                        Compaction.Unzip(path, CachePaths.UpdateDir);
                    }
                    catch (Exception ex) when(ex.IsCaught())
                    {
                        Log.Write(ex);
                    }
                    if (File.Exists(path))
                    {
                        break;
                    }
                }
            }
            notifyBox.Close();
        }
Exemplo n.º 7
0
 internal PDF417(bool compact)
 {
    this.compact = compact;
    compaction = Compaction.AUTO;
    encoding = PDF417HighLevelEncoder.DEFAULT_ENCODING;
    disableEci = false;
    minCols = 2;
    maxCols = 30;
    maxRows = 30;
    minRows = 2;
 }
Exemplo n.º 8
0
 internal PDF417(bool compact)
 {
    this.compact = compact;
    compaction = Compaction.AUTO;
    encoding = null; // use default
    disableEci = false;
    minCols = 2;
    maxCols = 30;
    maxRows = 30;
    minRows = 2;
 }
        /// <summary>
        /// Performs high-level encoding of a PDF417 message using the algorithm described in annex P
        /// of ISO/IEC 15438:2001(E). If byte compaction has been selected, then only byte compaction
        /// is used.
        /// </summary>
        /// <param name="msg">the message</param>
        /// <param name="compaction">compaction mode to use</param>
        /// <param name="encoding">character encoding used to encode in default or byte compaction
        /// or null for default / not applicable</param>
        /// <param name="disableEci">if true, don't add an ECI segment for different encodings than default</param>
        /// <returns>the encoded message (the char values range from 0 to 928)</returns>
        internal static String encodeHighLevel(String msg, Compaction compaction, Encoding encoding, bool disableEci)
        {
            //the codewords 0..928 are encoded as Unicode characters
            var sb = new StringBuilder(msg.Length);

            if (encoding != null && !disableEci && String.Compare(DEFAULT_ENCODING_NAME, encoding.WebName, StringComparison.Ordinal) != 0)
            {
                CharacterSetECI eci = CharacterSetECI.getCharacterSetECIByName(encoding.WebName);
                if (eci != null)
                {
                    encodingECI(eci.Value, sb);
                }
            }

            int len         = msg.Length;
            int p           = 0;
            int textSubMode = SUBMODE_ALPHA;

            // User selected encoding mode
            switch (compaction)
            {
            case Compaction.TEXT:
                encodeText(msg, p, len, sb, textSubMode);
                break;

            case Compaction.BYTE:
                var msgBytes = toBytes(msg, encoding);
                encodeBinary(msgBytes, p, msgBytes.Length, BYTE_COMPACTION, sb);
                break;

            case Compaction.NUMERIC:
                sb.Append((char)LATCH_TO_NUMERIC);
                encodeNumeric(msg, p, len, sb);
                break;

            default:
                int    encodingMode = TEXT_COMPACTION; //Default mode, see 4.4.2.1
                byte[] bytes        = null;
                while (p < len)
                {
                    int n = determineConsecutiveDigitCount(msg, p);
                    if (n >= 13)
                    {
                        sb.Append((char)LATCH_TO_NUMERIC);
                        encodingMode = NUMERIC_COMPACTION;
                        textSubMode  = SUBMODE_ALPHA; //Reset after latch
                        encodeNumeric(msg, p, n, sb);
                        p += n;
                    }
                    else
                    {
                        int t = determineConsecutiveTextCount(msg, p);
                        if (t >= 5 || n == len)
                        {
                            if (encodingMode != TEXT_COMPACTION)
                            {
                                sb.Append((char)LATCH_TO_TEXT);
                                encodingMode = TEXT_COMPACTION;
                                textSubMode  = SUBMODE_ALPHA; //start with submode alpha after latch
                            }
                            textSubMode = encodeText(msg, p, t, sb, textSubMode);
                            p          += t;
                        }
                        else
                        {
                            if (bytes == null)
                            {
                                bytes = toBytes(msg, encoding);
                            }
                            int b = determineConsecutiveBinaryCount(msg, bytes, p, encoding);
                            if (b == 0)
                            {
                                b = 1;
                            }
                            if (b == 1 && encodingMode == TEXT_COMPACTION)
                            {
                                //Switch for one byte (instead of latch)
                                encodeBinary(bytes, 0, 1, TEXT_COMPACTION, sb);
                            }
                            else
                            {
                                //Mode latch performed by encodeBinary()
                                encodeBinary(bytes,
                                             toBytes(msg.Substring(0, p), encoding).Length,
                                             toBytes(msg.Substring(p, b), encoding).Length,
                                             encodingMode,
                                             sb);
                                encodingMode = BYTE_COMPACTION;
                                textSubMode  = SUBMODE_ALPHA; //Reset after latch
                            }
                            p += b;
                        }
                    }
                }
                break;
            }

            return(sb.ToString());
        }
        /// <summary>
        /// Performs high-level encoding of a PDF417 message using the algorithm described in annex P
        /// of ISO/IEC 15438:2001(E). If byte compaction has been selected, then only byte compaction
        /// is used.
        ///
        /// <param name="msg">the message</param>
        /// <returns>the encoded message (the char values range from 0 to 928)</returns>
        /// </summary>
        internal static String encodeHighLevel(String msg, Compaction compaction)
        {
            byte[] bytes = null; //Fill later and only if needed

            //the codewords 0..928 are encoded as Unicode characters
            StringBuilder sb = new StringBuilder(msg.Length);

            int len         = msg.Length;
            int p           = 0;
            int textSubMode = SUBMODE_ALPHA;

            // User selected encoding mode
            if (compaction == Compaction.TEXT)
            {
                encodeText(msg, p, len, sb, textSubMode);
            }
            else if (compaction == Compaction.BYTE)
            {
                bytes = getBytesForMessage(msg);
                encodeBinary(bytes, p, bytes.Length, BYTE_COMPACTION, sb);
            }
            else if (compaction == Compaction.NUMERIC)
            {
                sb.Append((char)LATCH_TO_NUMERIC);
                encodeNumeric(msg, p, len, sb);
            }
            else
            {
                int encodingMode = TEXT_COMPACTION; //Default mode, see 4.4.2.1
                while (p < len)
                {
                    int n = determineConsecutiveDigitCount(msg, p);
                    if (n >= 13)
                    {
                        sb.Append((char)LATCH_TO_NUMERIC);
                        encodingMode = NUMERIC_COMPACTION;
                        textSubMode  = SUBMODE_ALPHA; //Reset after latch
                        encodeNumeric(msg, p, n, sb);
                        p += n;
                    }
                    else
                    {
                        int t = determineConsecutiveTextCount(msg, p);
                        if (t >= 5 || n == len)
                        {
                            if (encodingMode != TEXT_COMPACTION)
                            {
                                sb.Append((char)LATCH_TO_TEXT);
                                encodingMode = TEXT_COMPACTION;
                                textSubMode  = SUBMODE_ALPHA; //start with submode alpha after latch
                            }
                            textSubMode = encodeText(msg, p, t, sb, textSubMode);
                            p          += t;
                        }
                        else
                        {
                            if (bytes == null)
                            {
                                bytes = getBytesForMessage(msg);
                            }
                            int b = determineConsecutiveBinaryCount(msg, bytes, p);
                            if (b == 0)
                            {
                                b = 1;
                            }
                            if (b == 1 && encodingMode == TEXT_COMPACTION)
                            {
                                //Switch for one byte (instead of latch)
                                encodeBinary(bytes, p, 1, TEXT_COMPACTION, sb);
                            }
                            else
                            {
                                //Mode latch performed by encodeBinary()
                                encodeBinary(bytes, p, b, encodingMode, sb);
                                encodingMode = BYTE_COMPACTION;
                                textSubMode  = SUBMODE_ALPHA; //Reset after latch
                            }
                            p += b;
                        }
                    }
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 11
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Text = Resources.WindowTitle;
            TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate);
            if (!NetEx.InternetIsAvailable())
            {
                if (!_silent || !File.Exists(_appPath))
                {
                    MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Application.Exit();
                return;
            }
            var iniFile = Path.ChangeExtension(PathEx.LocalPath, ".ini");

            if (!File.Exists(iniFile))
            {
                Ini.SetFile(iniFile);
                Ini.Write("Settings", "Language", "English");
                Ini.Write("Settings", "Architecture", Environment.Is64BitProcess ? "64 bit" : "32 bit");
                Ini.Write("Settings", "DoNotAskAgain", false);
            }
            else
            {
                Ini.SetFile(iniFile);
            }
            if (!Ini.Read("Settings", "DoNotAskAgain", false))
            {
                Form langSelection = new LangSelectionForm();
                if (langSelection.ShowDialog() != DialogResult.OK)
                {
                    MessageBoxEx.Show(Resources.Msg_Hint_03, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Application.Exit();
                    return;
                }
            }
            var    lang   = $"{Ini.Read<string>("Settings", "Language", "English")} ({Ini.Read<string>("Settings", "Architecture", Environment.Is64BitProcess ? "64 bit" : "32 bit")})";
            var    source = NetEx.Transfer.DownloadString(Resources.RegexUrl);
            string updUrl = null;

            try
            {
                foreach (Match match in Regex.Matches(source, Resources.RegexLinePattern, RegexOptions.Singleline))
                {
                    var mLine = match.Groups[1].ToString();
                    var mLang = Regex.Match(mLine, Resources.RegexLanguagePattern, RegexOptions.Singleline).Groups[1].ToString();
                    if (string.IsNullOrWhiteSpace(mLang) || !mLang.EqualsEx(lang))
                    {
                        continue;
                    }
                    var mVer = Regex.Match(mLine, Resources.RegexVersionPattern, RegexOptions.Singleline).Groups[1].ToString();
                    if (string.IsNullOrWhiteSpace(mVer) || mVer.ContainsEx("trial", "free", "beta"))
                    {
                        continue;
                    }
                    var mName = Regex.Match(mLine, Resources.RegexFileNamePattern, RegexOptions.Singleline).Groups[1].ToString();
                    if (string.IsNullOrWhiteSpace(mName))
                    {
                        continue;
                    }
                    updUrl = string.Format(Resources.UpdateUrl, mName);
                    if (!NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent))
                    {
                        updUrl = null;
                        continue;
                    }
                    break;
                }
                if (string.IsNullOrEmpty(updUrl))
                {
                    throw new ArgumentNullException(nameof(updUrl));
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                if (!_silent || !File.Exists(_appPath))
                {
                    MessageBoxEx.Show(Resources.Msg_Warn_02, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                Application.Exit();
                return;
            }
            var localDate  = File.GetLastWriteTime(_appPath);
            var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent);

            if ((onlineDate - localDate).Days > 0)
            {
                if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}");
                    if (!File.Exists(archivePath))
                    {
                        _tmpDir = PathEx.Combine(Path.GetTempPath(), PathEx.GetTempDirName(Resources.AppName));
                        var hlpPath = Path.Combine(_tmpDir, "7z.zip");
                        ResourcesEx.Extract(Resources._7z, hlpPath, true);
                        Compaction.Unzip(hlpPath, _tmpDir);
                        _transfer.DownloadFile(updUrl, archivePath);
                        Opacity = 1f;
                        CheckDownload.Enabled = true;
                        return;
                    }
                    ExtractDownload.RunWorkerAsync();
                }
                Application.Exit();
                return;
            }
            if (!_silent)
            {
                MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            Application.Exit();
        }
Exemplo n.º 12
0
 /// <summary>
 /// Sets compaction to values stored in <see cref="Compaction"/>enum
 /// </summary>
 /// <param name="compaction">compaction mode to use</param>
 internal void setCompaction(Compaction compaction)
 {
     this.compaction = compaction;
 }
Exemplo n.º 13
0
 internal PDF417(bool compact)
 {
    this.compact = compact;
    compaction = Compaction.AUTO;
    minCols = 2;
    maxCols = 30;
    maxRows = 30;
    minRows = 2;
 }
Exemplo n.º 14
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Text = Resources.WindowTitle;
            TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate);
            if (!NetEx.InternetIsAvailable())
            {
                if (!_silent || !File.Exists(_appPath))
                {
                    MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Application.Exit();
                return;
            }
            string updUrl = null;

            try
            {
                var source = NetEx.Transfer.DownloadString(Resources.RegexFirstUrl);
                if (string.IsNullOrWhiteSpace(source))
                {
                    throw new ArgumentNullException(nameof(source));
                }
                source = TextEx.FormatNewLine(source).SplitNewLine().SkipWhile(x => !x.ContainsEx(Resources.RegexSecBtnMatch)).Take(1).Join();
                foreach (Match match in Regex.Matches(source, Resources.RegexSecUrlPattern, RegexOptions.Singleline))
                {
                    var mUrl = match.Groups[1].ToString();
                    if (string.IsNullOrWhiteSpace(mUrl))
                    {
                        continue;
                    }
                    source = NetEx.Transfer.DownloadString(mUrl);
                    if (string.IsNullOrWhiteSpace(source))
                    {
                        throw new ArgumentNullException(nameof(source));
                    }
                    source = TextEx.FormatNewLine(source).SplitNewLine().SkipWhile(x => !x.ContainsEx(Resources.RegexThirdBtnMatch) || !Resources.RegexThirdExtMatch.SplitNewLine().Any(y => x.ContainsEx(y))).Take(1).Join();
                    foreach (Match match2 in Regex.Matches(source, Resources.RegexThirdUrlPattern, RegexOptions.Singleline))
                    {
                        mUrl = match2.Groups[1].ToString();
                        if (string.IsNullOrWhiteSpace(mUrl))
                        {
                            continue;
                        }
                        if (mUrl.ContainsEx("/show/"))
                        {
                            mUrl = mUrl.Replace("/show/", "/get/");
                        }
                        updUrl = mUrl;
                        break;
                    }
                    break;
                }
                if (!NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent))
                {
                    throw new PathNotFoundException(updUrl);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                if (!_silent || !File.Exists(_appPath))
                {
                    MessageBoxEx.Show(Resources.Msg_Warn_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                Application.Exit();
                return;
            }
            var localDate  = File.GetLastWriteTime(_appPath);
            var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent);

            if ((onlineDate - localDate).Days > 0)
            {
                if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}");
                    if (!File.Exists(archivePath))
                    {
                        _tmpDir = PathEx.Combine(Path.GetTempPath(), PathEx.GetTempDirName(Resources.AppName));
                        var hlpPath = Path.Combine(_tmpDir, "iu.zip");
                        ResourcesEx.Extract(Resources.iu, hlpPath, true);
                        Compaction.Unzip(hlpPath, _tmpDir);
                        _transfer.DownloadFile(updUrl, archivePath);
                        Opacity = 1f;
                        CheckDownload.Enabled = true;
                        return;
                    }
                    ExtractDownload.RunWorkerAsync();
                }
                Application.Exit();
                return;
            }
            if (!_silent)
            {
                MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            Application.Exit();
        }
Exemplo n.º 15
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Text = Resources.WindowTitle;
            TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate);
            if (!NetEx.InternetIsAvailable())
            {
                if (!_silent || !File.Exists(_appPath))
                {
                    MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Application.Exit();
                return;
            }
            string updUrl;

            try
            {
                updUrl = string.Format(Resources.UpdateUrl,
#if x86
                                       "x86"
#else
                                       "x64"
#endif
                                       );
                if (!NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent))
                {
                    throw new PathNotFoundException(updUrl);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                if (!_silent || !File.Exists(_appPath))
                {
                    MessageBoxEx.Show(Resources.Msg_Warn_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                Application.Exit();
                return;
            }
            var appPath    = PathEx.Combine(Resources.AppPath);
            var localDate  = File.GetLastWriteTime(appPath);
            var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent);
            if ((onlineDate - localDate).Days > 0)
            {
                if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}");
                    if (!File.Exists(archivePath))
                    {
                        _tmpDir = PathEx.Combine(Path.GetTempPath(), PathEx.GetTempDirName(Resources.AppName));
                        var hlpPath = Path.Combine(_tmpDir, "iu.zip");
                        ResourcesEx.Extract(Resources.iu, hlpPath, true);
                        Compaction.Unzip(hlpPath, _tmpDir);
                        _transfer.DownloadFile(updUrl, archivePath);
                        Opacity = 1f;
                        CheckDownload.Enabled = true;
                        return;
                    }
                    ExtractDownload.RunWorkerAsync();
                }
                Application.Exit();
                return;
            }
            if (!_silent)
            {
                MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            Application.Exit();
        }
Exemplo n.º 16
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Text = Resources.WindowTitle;
            TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate);
            if (!NetEx.InternetIsAvailable())
            {
                if (!_silent || !File.Exists(_appPath))
                {
                    MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Application.Exit();
                return;
            }
            string updUrl;

            try
            {
                var mirrors   = Resources.UpdateMirrors.SplitNewLine();
                var mirrorMap = new Dictionary <long, string>();
                foreach (var url in mirrors)
                {
                    var ping = NetEx.Ping(url);
                    while (mirrorMap.ContainsKey(ping))
                    {
                        ping++;
                    }
                    mirrorMap.Add(ping, url);
                }
                var sortedPings = mirrorMap.Keys.ToList();
                sortedPings.Sort();
                var bestPing = sortedPings.Min();
                var mirror   = mirrorMap[bestPing];
                var source   = NetEx.Transfer.DownloadString(string.Format(Resources.RegexUrl, mirror));
                if (string.IsNullOrWhiteSpace(source))
                {
                    foreach (var ping in sortedPings)
                    {
                        source = NetEx.Transfer.DownloadString(string.Format(Resources.RegexUrl, ping));
                        break;
                    }
                }
                if (string.IsNullOrWhiteSpace(source))
                {
                    throw new ArgumentNullException(nameof(source));
                }
                var vers = new List <Version>();
                foreach (Match match in Regex.Matches(source, Resources.RegexVersionPattern, RegexOptions.Singleline))
                {
                    var mVer = match.Groups[1].ToString();
                    if (string.IsNullOrWhiteSpace(mVer))
                    {
                        continue;
                    }
                    var cVer = mVer.ToCharArray();
                    if (!cVer.Count(char.IsDigit).IsBetween(3, 16) || !cVer.Count(c => c == '.').IsBetween(2, 3))
                    {
                        continue;
                    }
                    mVer = new string(mVer.Where(c => char.IsDigit(c) || c == '.').ToArray());
                    if (!Version.TryParse(mVer, out Version ver))
                    {
                        continue;
                    }
                    vers.Add(ver);
                }
                _ver   = vers.Max();
                updUrl = string.Format(Resources.UpdateUrl, mirror, _ver,
#if x86
                                       "32"
#else
                                       "64"
#endif
                                       );
                var exists = NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent);
                if (!exists)
                {
                    foreach (var ping in sortedPings)
                    {
                        updUrl = string.Format(Resources.UpdateUrl, mirrorMap[ping], _ver,
#if x86
                                               "32"
#else
                                               "64"
#endif
                                               );
                        exists = NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent);
                        if (exists)
                        {
                            break;
                        }
                    }
                }
                if (!exists)
                {
                    throw new PathNotFoundException(updUrl);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                if (!_silent || !File.Exists(_appPath))
                {
                    MessageBoxEx.Show(Resources.Msg_Warn_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                Application.Exit();
                return;
            }
            var localDate  = File.GetLastWriteTime(_appPath);
            var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent);
            if ((onlineDate - localDate).Days > 0)
            {
                if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}");
                    if (!File.Exists(archivePath))
                    {
                        _tmpDir = PathEx.Combine(Path.GetTempPath(), PathEx.GetTempDirName(Resources.AppName));
                        var hlpPath = Path.Combine(_tmpDir, "7z.zip");
                        ResourcesEx.Extract(Resources._7z, hlpPath, true);
                        Compaction.Unzip(hlpPath, _tmpDir);
                        _transfer.DownloadFile(updUrl, archivePath);
                        Opacity = 1f;
                        CheckDownload.Enabled = true;
                        return;
                    }
                    ExtractDownload.RunWorkerAsync();
                }
                Application.Exit();
                return;
            }
            if (!_silent)
            {
                MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            Application.Exit();
        }
Exemplo n.º 17
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Text = Resources.WindowTitle;
            TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate);
            if (!NetEx.InternetIsAvailable())
            {
                if (!_silent || !File.Exists(_appPath))
                {
                    MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Application.Exit();
                return;
            }
            string updUrl = null;

            try
            {
                var source = NetEx.Transfer.DownloadString(Resources.RegexUrl);
                if (string.IsNullOrWhiteSpace(source))
                {
                    throw new ArgumentNullException(nameof(source));
                }
                var paths = new Dictionary <Version, string>();
                foreach (Match match in Regex.Matches(source, Resources.RegexPattern, RegexOptions.Singleline))
                {
                    var mPath = match.Groups[1].ToString();
                    if (string.IsNullOrWhiteSpace(mPath) || mPath.Count(c => c == '/') != 1)
                    {
                        continue;
                    }
                    var mVer = mPath.Split('/').FirstOrDefault();
                    if (string.IsNullOrEmpty(mVer) || !mVer.All(c => char.IsDigit(c) || c == '.'))
                    {
                        continue;
                    }
                    if (!Version.TryParse(mVer, out Version ver) || paths.ContainsKey(ver))
                    {
                        continue;
                    }
                    paths.Add(ver, mPath);
                }
                updUrl = string.Format(Resources.UpdateUrl, paths[paths.Keys.Max()]);
                if (!NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent))
                {
                    throw new PathNotFoundException(updUrl);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                if (!_silent || !File.Exists(_appPath))
                {
                    MessageBoxEx.Show(Resources.Msg_Warn_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                Application.Exit();
            }
            var localDate  = File.GetLastWriteTime(_appPath);
            var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent);

            if ((onlineDate - localDate).Days > 0)
            {
                if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}");
                    if (!File.Exists(archivePath))
                    {
                        _tmpDir = PathEx.Combine(Path.GetTempPath(), PathEx.GetTempDirName(Resources.AppName));
                        var hlpPath = Path.Combine(_tmpDir, "iu.zip");
                        ResourcesEx.Extract(Resources.iu, hlpPath, true);
                        Compaction.Unzip(hlpPath, _tmpDir);
                        _transfer.DownloadFile(updUrl, archivePath);
                        Opacity = 1f;
                        CheckDownload.Enabled = true;
                        return;
                    }
                    ExtractDownload.RunWorkerAsync();
                }
                Application.Exit();
                return;
            }
            if (!_silent)
            {
                MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            Application.Exit();
        }
Exemplo n.º 18
0
 public BitMatrix encode(String contents,
                          BarcodeFormat format,
                          bool compact,
                          int width,
                          int height,
                          int minCols,
                          int maxCols,
                          int minRows,
                          int maxRows,
                          Compaction compaction)
 {
    IDictionary<EncodeHintType, Object> hints = new Dictionary<EncodeHintType, Object>();
    hints[EncodeHintType.PDF417_COMPACT] = compact;
    hints[EncodeHintType.PDF417_COMPACTION] = compaction;
    hints[EncodeHintType.PDF417_DIMENSIONS] = new Dimensions(minCols, maxCols, minRows, maxRows);
    return encode(contents, format, width, height, hints);
 }
Exemplo n.º 19
0
 /// <summary>
 /// Sets compaction to values stored in <see cref="Compaction" />enum
 /// </summary>
 internal void setCompaction(Compaction compaction)
 {
    this.compaction = compaction;
 }
Exemplo n.º 20
0
      /// <summary>
      /// Performs high-level encoding of a PDF417 message using the algorithm described in annex P
      /// of ISO/IEC 15438:2001(E). If byte compaction has been selected, then only byte compaction
      /// is used.
      ///
      /// <param name="msg">the message</param>
      /// <returns>the encoded message (the char values range from 0 to 928)</returns>
      /// </summary>
      internal static String encodeHighLevel(String msg, Compaction compaction)
      {
         byte[] bytes = null; //Fill later and only if needed

         //the codewords 0..928 are encoded as Unicode characters
         StringBuilder sb = new StringBuilder(msg.Length);

         int len = msg.Length;
         int p = 0;
         int textSubMode = SUBMODE_ALPHA;

         // User selected encoding mode
         if (compaction == Compaction.TEXT)
         {
            encodeText(msg, p, len, sb, textSubMode);

         }
         else if (compaction == Compaction.BYTE)
         {
            bytes = getBytesForMessage(msg);
            encodeBinary(bytes, p, bytes.Length, BYTE_COMPACTION, sb);

         }
         else if (compaction == Compaction.NUMERIC)
         {
            sb.Append((char)LATCH_TO_NUMERIC);
            encodeNumeric(msg, p, len, sb);

         }
         else
         {
            int encodingMode = TEXT_COMPACTION; //Default mode, see 4.4.2.1
            while (p < len)
            {
               int n = determineConsecutiveDigitCount(msg, p);
               if (n >= 13)
               {
                  sb.Append((char)LATCH_TO_NUMERIC);
                  encodingMode = NUMERIC_COMPACTION;
                  textSubMode = SUBMODE_ALPHA; //Reset after latch
                  encodeNumeric(msg, p, n, sb);
                  p += n;
               }
               else
               {
                  int t = determineConsecutiveTextCount(msg, p);
                  if (t >= 5 || n == len)
                  {
                     if (encodingMode != TEXT_COMPACTION)
                     {
                        sb.Append((char)LATCH_TO_TEXT);
                        encodingMode = TEXT_COMPACTION;
                        textSubMode = SUBMODE_ALPHA; //start with submode alpha after latch
                     }
                     textSubMode = encodeText(msg, p, t, sb, textSubMode);
                     p += t;
                  }
                  else
                  {
                     if (bytes == null)
                     {
                        bytes = getBytesForMessage(msg);
                     }
                     int b = determineConsecutiveBinaryCount(msg, bytes, p);
                     if (b == 0)
                     {
                        b = 1;
                     }
                     if (b == 1 && encodingMode == TEXT_COMPACTION)
                     {
                        //Switch for one byte (instead of latch)
                        encodeBinary(bytes, p, 1, TEXT_COMPACTION, sb);
                     }
                     else
                     {
                        //Mode latch performed by encodeBinary()
                        encodeBinary(bytes, p, b, encodingMode, sb);
                        encodingMode = BYTE_COMPACTION;
                        textSubMode = SUBMODE_ALPHA; //Reset after latch
                     }
                     p += b;
                  }
               }
            }
         }

         return sb.ToString();
      }
      /// <summary>
      /// Performs high-level encoding of a PDF417 message using the algorithm described in annex P
      /// of ISO/IEC 15438:2001(E). If byte compaction has been selected, then only byte compaction
      /// is used.
      /// </summary>
      /// <param name="msg">the message</param>
      /// <param name="compaction">compaction mode to use</param>
      /// <param name="encoding">character encoding used to encode in default or byte compaction
      /// or null for default / not applicable</param>
      /// <param name="disableEci">if true, don't add an ECI segment for different encodings than default</param>
      /// <returns>the encoded message (the char values range from 0 to 928)</returns>
      internal static String encodeHighLevel(String msg, Compaction compaction, Encoding encoding, bool disableEci)
      {
         //the codewords 0..928 are encoded as Unicode characters
         var sb = new StringBuilder(msg.Length);

         if (encoding != null && !disableEci && String.Compare(DEFAULT_ENCODING_NAME, encoding.WebName, StringComparison.Ordinal) != 0)
         {
            CharacterSetECI eci = CharacterSetECI.getCharacterSetECIByName(encoding.WebName);
            if (eci != null)
            {
               encodingECI(eci.Value, sb);
            }
         }

         int len = msg.Length;
         int p = 0;
         int textSubMode = SUBMODE_ALPHA;

         // User selected encoding mode
         byte[] bytes = null; //Fill later and only if needed
         if (compaction == Compaction.TEXT)
         {
            encodeText(msg, p, len, sb, textSubMode);

         }
         else if (compaction == Compaction.BYTE)
         {
            bytes = toBytes(msg, encoding);
            encodeBinary(bytes, p, bytes.Length, BYTE_COMPACTION, sb);

         }
         else if (compaction == Compaction.NUMERIC)
         {
            sb.Append((char) LATCH_TO_NUMERIC);
            encodeNumeric(msg, p, len, sb);

         }
         else
         {
            int encodingMode = TEXT_COMPACTION; //Default mode, see 4.4.2.1
            while (p < len)
            {
               int n = determineConsecutiveDigitCount(msg, p);
               if (n >= 13)
               {
                  sb.Append((char) LATCH_TO_NUMERIC);
                  encodingMode = NUMERIC_COMPACTION;
                  textSubMode = SUBMODE_ALPHA; //Reset after latch
                  encodeNumeric(msg, p, n, sb);
                  p += n;
               }
               else
               {
                  int t = determineConsecutiveTextCount(msg, p);
                  if (t >= 5 || n == len)
                  {
                     if (encodingMode != TEXT_COMPACTION)
                     {
                        sb.Append((char) LATCH_TO_TEXT);
                        encodingMode = TEXT_COMPACTION;
                        textSubMode = SUBMODE_ALPHA; //start with submode alpha after latch
                     }
                     textSubMode = encodeText(msg, p, t, sb, textSubMode);
                     p += t;
                  }
                  else
                  {
                     if (bytes == null)
                     {
                        bytes = toBytes(msg, encoding);
                     }
                     int b = determineConsecutiveBinaryCount(msg, bytes, p);
                     if (b == 0)
                     {
                        b = 1;
                     }
                     if (b == 1 && encodingMode == TEXT_COMPACTION)
                     {
                        //Switch for one byte (instead of latch)
                        encodeBinary(bytes, p, 1, TEXT_COMPACTION, sb);
                     }
                     else
                     {
                        //Mode latch performed by encodeBinary()
                        encodeBinary(bytes,
                                     toBytes(msg.Substring(0, p), encoding).Length,
                                     toBytes(msg.Substring(p, b), encoding).Length,
                                     encodingMode,
                                     sb);
                        encodingMode = BYTE_COMPACTION;
                        textSubMode = SUBMODE_ALPHA; //Reset after latch
                     }
                     p += b;
                  }
               }
            }
         }

         return sb.ToString();
      }
Exemplo n.º 22
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Text = Resources.WindowTitle;
            TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate);
            if (!NetEx.InternetIsAvailable())
            {
                if (!_silent || !File.Exists(_appPath))
                {
                    MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Application.Exit();
                return;
            }
            string updUrl = null;

            try
            {
                var regexUrl = Resources.RegexUrl;
                if (!Ini.ReadDirect("Settings", "BetaUpdates").EqualsEx("1", "True"))
                {
                    regexUrl += "/latest";
                }
                var source = NetEx.Transfer.DownloadString(regexUrl);
                if (string.IsNullOrWhiteSpace(source))
                {
                    throw new ArgumentNullException(nameof(source));
                }
                source = TextEx.FormatNewLine(source);
#if x86
                const string arch = "32";
#else
                const string arch = "64";
#endif
                source = source.SplitNewLine().Where(x => x.ContainsEx(Resources.SearchPrefix) && x.ContainsEx(string.Format(Resources.SearchSuffix, arch))).Take(1).Join();
                foreach (Match match in Regex.Matches(source, Resources.RegexPattern, RegexOptions.Singleline))
                {
                    var mPath = match.Groups[1].ToString();
                    if (string.IsNullOrWhiteSpace(mPath) || mPath.Count(c => c == '/') != 1)
                    {
                        continue;
                    }
                    updUrl = string.Format(Resources.UpdateUrl, mPath);
                    break;
                }
                if (!NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent))
                {
                    throw new PathNotFoundException(updUrl);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                if (!_silent || !File.Exists(_appPath))
                {
                    MessageBoxEx.Show(Resources.Msg_Warn_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                Application.Exit();
            }
            var localDate  = File.GetLastWriteTime(_appPath);
            var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent);
            if ((onlineDate - localDate).Days > 0)
            {
                if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}");
                    if (!File.Exists(archivePath))
                    {
                        _tmpDir = PathEx.Combine(Path.GetTempPath(), PathEx.GetTempDirName(Resources.AppName));
                        var hlpPath = Path.Combine(_tmpDir, "7z.zip");
                        ResourcesEx.Extract(Resources._7z, hlpPath, true);
                        Compaction.Unzip(hlpPath, _tmpDir);
                        _transfer.DownloadFile(updUrl, archivePath);
                        Opacity = 1f;
                        CheckDownload.Enabled = true;
                        return;
                    }
                    ExtractDownload.RunWorkerAsync();
                }
                Application.Exit();
                return;
            }
            if (!_silent)
            {
                MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            Application.Exit();
        }
Exemplo n.º 23
0
 /// <summary>
 /// The compaction style. Default: kCompactionStyleLevel
 /// </summary>
 public ColumnFamilyOptions SetCompactionStyle(Compaction value)
 {
     Native.Instance.rocksdb_options_set_compaction_style(Handle, value);
     return(this);
 }
Exemplo n.º 24
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Text = Resources.WindowTitle;
            TaskBar.Progress.SetState(Handle, TaskBar.Progress.Flags.Indeterminate);
            if (!NetEx.InternetIsAvailable())
            {
                if (!_silent || !File.Exists(_appPath))
                {
                    MessageBoxEx.Show(Resources.Msg_Err_00, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Application.Exit();
                return;
            }
            string updUrl = null;

            try
            {
                _tmpDir = PathEx.Combine(Path.GetTempPath(), PathEx.GetTempDirName(Resources.AppDisplayName));
                var hlpPath = Path.Combine(_tmpDir, "js.zip");
                ResourcesEx.Extract(Resources.js, hlpPath, true);
                Compaction.Unzip(hlpPath, _tmpDir);
                Thread.Sleep(200);
                var helperPath = Path.Combine(_tmpDir, "read.js");
                var source     = Path.Combine(_tmpDir, "source.txt");
                File.WriteAllText(helperPath, Resources.JsScript);
                using (var p = ProcessEx.Send(string.Format(Resources.RunScript, _tmpDir), Elevation.IsAdministrator, ProcessWindowStyle.Hidden, false))
                    if (p?.HasExited == false)
                    {
                        p.WaitForExit();
                    }
                source = File.ReadAllText(source);
                if (string.IsNullOrWhiteSpace(source))
                {
                    throw new ArgumentNullException(nameof(source));
                }
                source = TextEx.FormatNewLine(source).SplitNewLine().SkipWhile(x => !x.ContainsEx(".exe")).Take(1).Join();
                foreach (Match match in Regex.Matches(source, Resources.RegexUrlPattern, RegexOptions.Singleline))
                {
                    var mUrl = match.Groups[1].ToString();
                    if (string.IsNullOrWhiteSpace(mUrl))
                    {
                        continue;
                    }
                    updUrl = mUrl.Trim('"');
                    break;
                }
                if (!NetEx.FileIsAvailable(updUrl, 60000, Resources.UserAgent))
                {
                    throw new PathNotFoundException(updUrl);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                if (!_silent || !File.Exists(_appPath))
                {
                    MessageBoxEx.Show(Resources.Msg_Warn_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                Application.Exit();
                return;
            }
            var localDate  = File.GetLastWriteTime(_appPath);
            var onlineDate = NetEx.GetFileDate(updUrl, Resources.UserAgent);

            if ((onlineDate - localDate).Days > 0)
            {
                if (_silent || MessageBoxEx.Show(Resources.Msg_Hint_00, Resources.WindowTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    var archivePath = PathEx.Combine(PathEx.LocalDir, $"..\\{PathEx.GetTempFileName()}");
                    if (!File.Exists(archivePath))
                    {
                        var hlpPath = Path.Combine(_tmpDir, "iu.zip");
                        ResourcesEx.Extract(Resources.iu, hlpPath, true);
                        Compaction.Unzip(hlpPath, _tmpDir);
                        _transfer.DownloadFile(updUrl, archivePath);
                        Opacity = 1f;
                        CheckDownload.Enabled = true;
                        return;
                    }
                    ExtractDownload.RunWorkerAsync();
                }
                Application.Exit();
                return;
            }
            if (!_silent)
            {
                MessageBoxEx.Show(Resources.Msg_Hint_01, Resources.WindowTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            Application.Exit();
        }