Esempio n. 1
0
 /// <summary>
 /// Try to acess the registery key wich contain the prolog path
 /// </summary>
 /// <returns></returns>
 private bool findPrologFromReg()
 {
     try
     {
         stringPrologFolder = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\SWI\Prolog", "home", null);
         if (stringPrologFolder != null)
         {
             MessageBox.Show(stringPrologFolder);
             if (File.Exists(stringPrologFolder + @"\bin\plcon.exe"))
             {
                 //Hiding all that is unnecessary and put the correct path
                 //TODO : To factorise !
                 textBox_PrologFolder.Text    = stringPrologFolder;
                 label_PrologFolder.Visible   = false;
                 textBox_PrologFolder.Visible = false;
                 textBox_Status.Text          = textBox_Status.Text + "Prolog found. ";
                 stringPrologFolder           = null;
                 return(true);
             }
         }
     }
     catch (IOException IOEx)
     {
         MessageBox.Show("An input output exception was raised \n" + IOEx.ToString());
     }
     catch (ArgumentException ArguEx)
     {
         MessageBox.Show("An ArgumentException exception was raised \n" + ArguEx.ToString());
     }
     stringPrologFolder = null;
     return(false);
 }
 private void Import(byte[] io)
 {
     CheckReadOnly();
     if (Blob?.Any() != true)
     {
         return;
     }
     if (io != null)
     {
         for (int i = 0, ix = 0, len = Blob.Length; ix < len; ix++)
         {
             if (i >= io.Length)
             {
                 Blob[ix] = 0;
             }
             else if (i + sizeof(ulong) < io.Length)
             {
                 Blob[ix] = IOEx.GetUInt64(io, ref i, false);
             }
             else
             {
                 byte[] b = new byte[sizeof(ulong)];
                 Array.Copy(io, i, b, 0, io.Length - i);
                 int ii = 0;
                 Blob[ix] = IOEx.GetUInt64(b, ref ii, false);
                 i        = io.Length;
             }
         }
     }
     else
     {
         Blob.Fill(0UL);
     }
 }
Esempio n. 3
0
        // These are duplicated from IgorRuntimeUtils.cs in the Core module.  This was necessary to
        // keep the updater working, but they are overridden by the RuntimeUtils version once Core is
        // installed.  If you have any fixes for these two functions, fix them both here and in
        // IgorRuntimeUtils.cs.
        public static bool CopyFile(string SourceFile, string TargetFile)
        {
            if (File.Exists(SourceFile))
            {
                if (File.Exists(TargetFile))
                {
                    DeleteFile(TargetFile);
                }

                try
                {
                    File.Copy(SourceFile, TargetFile);
                }
                catch (System.IO.IOException IOEx)
                {
                    if (IOEx.GetHashCode() == 112)
                    {
                        IgorDebug.CoreCriticalError("Failed to copy file " + SourceFile + " to " + TargetFile + " because there is not enough free space at the target location.");
                    }

                    throw IOEx;

                    return(false);
                }

                return(true);
            }

            return(false);
        }
Esempio n. 4
0
        /* Get resolvers. */

        /// <summary>
        /// Retrieves a summary of all updates to be performed.
        /// </summary>
        public async Task <ModUpdateSummary> GetUpdateDetails()
        {
            if (_resolversWithUpdates == null)
            {
                var resolverManagerPairs = new List <ResolverManagerModResultPair>();
                var resolverTuples       = GetResolvers();
                foreach (var resolverTuple in resolverTuples)
                {
                    var modTuple = resolverTuple.ModTuple;
                    var version  = resolverTuple.Resolver.GetCurrentVersion();

                    // Note: Since R2R Support was added, we cannot predict which DLL will be in use. Just return the config file as main file.
                    string filePath = modTuple.Path;
                    var    metadata = new AssemblyMetadata(IOEx.ForceValidFilePath(modTuple.Config.ModName), version, filePath);

                    var manager      = new UpdateManager(metadata, resolverTuple.Resolver, resolverTuple.Resolver.Extractor);
                    var updateResult = await manager.CheckForUpdatesAsync();

                    if (updateResult.CanUpdate)
                    {
                        resolverManagerPairs.Add(new ResolverManagerModResultPair(resolverTuple.Resolver, manager, updateResult, modTuple));
                    }
                    else
                    {
                        resolverTuple.Resolver.PostUpdateCallback(false);
                    }
                }

                _resolversWithUpdates = resolverManagerPairs;
                return(new ModUpdateSummary(_resolversWithUpdates));
            }

            return(new ModUpdateSummary(_resolversWithUpdates));
        }
Esempio n. 5
0
        /* Save Mod to Directory */
        public void Save()
        {
            // Make folder path and save folder.
            string modConfigDirectory = IoC.Get <LoaderConfig>().ModConfigDirectory;
            string modDirectory       = Path.Combine(modConfigDirectory, IOEx.ForceValidFilePath(Config.ModId));

            Directory.CreateDirectory(modDirectory);

            // Save Config
            string configSaveDirectory = Path.Combine(modDirectory, ModConfig.ConfigFileName);
            string iconSaveDirectory   = Path.Combine(modDirectory, ModConfig.IconFileName);

            Config.ModIcon         = ModConfig.IconFileName;
            Config.ModDependencies = Dependencies.Where(x => x.Enabled).Select(x => x.Generic.ModId).ToArray();
            Config.SupportedAppId  = Constants.EmptyStringArray;

            ConfigReader <ModConfig> .WriteConfiguration(configSaveDirectory, (ModConfig)Config);

            // Save Image
            var encoder = new PngBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create((BitmapImage)Image));
            using (FileStream stream = new FileStream(iconSaveDirectory, FileMode.OpenOrCreate))
            {
                encoder.Save(stream);
            }
        }
        /// <summary>
        /// Downloads a specific file.
        /// </summary>
        public async Task DownloadAndExtract(DownloadProgressChangedEventHandler progressChanged)
        {
            // Start the modification download.
            byte[] data;
            using (WebClient client = new WebClient())
            {
                client.DownloadProgressChanged += progressChanged;
                data = await client.DownloadDataTaskAsync(Uri);
            }

            /* Extract to Temp Directory */
            string temporaryDirectory = GetTemporaryDirectory();
            var    archiveExtractor   = new ArchiveExtractor();
            await archiveExtractor.ExtractPackageAsync(data, temporaryDirectory);

            /* Get name of package. */
            var configReader = new ConfigReader <ModConfig>();
            var configs      = configReader.ReadConfigurations(temporaryDirectory, ModConfig.ConfigFileName);
            var loaderConfig = LoaderConfigReader.ReadConfiguration();

            foreach (var config in configs)
            {
                string configId        = config.Object.ModId;
                string configDirectory = Path.GetDirectoryName(config.Path);
                string targetDirectory = Path.Combine(loaderConfig.ModConfigDirectory, configId);
                IOEx.MoveDirectory(configDirectory, targetDirectory);
            }

            Directory.Delete(temporaryDirectory, true);
        }
    /// <summary>
    /// Retrieves an user config folder for a given mod.
    /// </summary>
    /// <param name="modId">Id for the mod to get the user config for.</param>
    /// <param name="configDirectory">The directory containing the user configurations.</param>
    public static string GetUserConfigFolderForMod(string modId, string configDirectory = null)
    {
        if (configDirectory == null)
        {
            configDirectory = IConfig <LoaderConfig> .FromPathOrDefault(Paths.LoaderConfigPath).GetModUserConfigDirectory();
        }

        return(Path.Combine(configDirectory, IOEx.ForceValidFilePath(modId)));
    }
        public static bool?GetBool(object val, bool parse)
        {
            if (val == null)
            {
                return(null);
            }
            try {
                TypeCode tc = val.GetTypeCode();
                switch (tc)
                {
                case TypeCode.String:
                    if (!parse)
                    {
                        return(null);
                    }
                    bool   n;
                    string s = StringEx.UserText(val as string);
                    if (s == null)
                    {
                        return(null);
                    }
                    if (TryFromServer(s, out n, false))
                    {
                        return(n);
                    }
                    switch (s[0])
                    {
                    case 'T':
                    case 't':
                    case '1': return(true);

                    case 'F':
                    case 'f':
                    case '0': return(false);

                    default: return(null);
                    }

                default:
                    if (IsNumeric(tc))
                    {
                        return(Convert.ToBoolean(val));
                    }
                    byte[] b  = val as byte[];
                    int    ix = 0;
                    if (b?.Length == sizeof(bool))
                    {
                        return(IOEx.GetBool(b, ref ix));
                    }
                    return(null);
                }
            } catch { return(null); }
        }
    private async Task ExtractReloadedAsync(string extractFolderPath, string downloadedPackagePath, IProgress <double> slice)
    {
        CurrentStepDescription = "Extracting Reloaded II";
        var extractor = new ZipPackageExtractor();
        await extractor.ExtractPackageAsync(downloadedPackagePath, extractFolderPath, slice, CancellationToken.Token);

        if (Native.IsDirectoryEmpty(extractFolderPath))
        {
            throw new Exception($"Reloaded failed to download (downloaded archive was not properly extracted).");
        }

        IOEx.TryDeleteFile(downloadedPackagePath);
    }
        private byte[] Export()
        {
            int len = Math.Min(Blob?.Length ?? 0, (int)Math.Ceiling(Max / bitsper));

            byte[] ret = new byte[len];
            int    ix  = 0;

            for (int i = 0; i < len; i++)
            {
                IOEx.Put(Blob[i], ret, ref ix, false, len - ix);
            }
            return(ret);
        }
        public static string ToJSValueStr(this object obj, Func <double, int, string> fmtnum = null, int precision = 3, string quote = null)
        {
            if (obj == null)
            {
                return(null);
            }
            try {
                IOEx.TypeCodeEx ext;
                switch (IOEx.GetTypeCode(ref obj, out ext))
                {
                case TypeCode.Single: double f = ((float)obj).FloatToDouble(); return(!f.IsValid() ? null : fmtnum != null?fmtnum(f, precision) : Math.Round(f, precision).ToString());

                case TypeCode.Double: double d = (double)obj; return(!d.IsValid() ? null : fmtnum != null?fmtnum(d, precision) : Math.Round(d, precision).ToString());

                case TypeCode.Decimal: return(fmtnum != null?fmtnum((double)decimal.Round((decimal)obj, precision), precision) : decimal.Round((decimal)obj, precision).ToString());

                case TypeCode.String: return(string.Concat(quote, ToString(obj, null), quote).UserText());

                case TypeCode.DateTime:
                    switch (ext)
                    {
                    case IOEx.TypeCodeEx.NullableTimeSpan:
                    case IOEx.TypeCodeEx.TimeSpan:
                        TimeSpan?ts = DateTimeEx.GetTime(obj, true);
                        return(ts == null ? null : string.Concat(quote, DateTimeEx.ToTimeString(ts.Value), quote).UserText());

                    default:
                        DateTimeOffset?dt = DateTimeEx.GetDate(obj, true, true);
                        return(dt == null ? null : string.Concat(quote, dt?.UtcDateTime.ToJSDateStr(), quote).UserText());
                    }

                case TypeCode.Object:
                    switch (ext)
                    {
                    case IOEx.TypeCodeEx.ByteArray: return(string.Concat(quote, Convert.ToBase64String(obj as byte[] ?? IOEx.Empty), quote).UserText());

                    case IOEx.TypeCodeEx.Guid: return(string.Concat(quote, (Guid)obj, quote).UserText());
                    }
                    object[] arr = obj is IEnumerable ? ((IEnumerable)obj)?.Enumerate(typeof(object)).ToArray() : null;
                    if (arr == null)
                    {
                        break;
                    }
                    return(string.Concat(quote?.Length > 0 ? "[" : null, string.Join(CommaSep, arr.Select(z => ReferenceEquals(z, obj) ? null : ToJSValueStr(z, fmtnum, precision, quote))), quote?.Length > 0 ? "]" : null));
                }
                return(ToString(obj, null));
            } catch {
                return(null);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Extracts the content files of the NuGet package to a specified directory.
        /// </summary>
        /// <param name="stream">Stream containing the NuGet package.</param>
        /// <param name="targetDirectory">The directory to extract the package content to.</param>
        /// <param name="token">A cancellation token to allow cancellation of the task.</param>
        public static void ExtractPackage(Stream stream, string targetDirectory, CancellationToken token = default)
        {
            PackageReaderBase packageReader = new PackageArchiveReader(stream);
            var items         = packageReader.GetFiles();
            var tempDirectory = $"{Path.GetTempPath()}\\{packageReader.NuspecReader.GetId()}";

            // Remove all items ending with a front or backslash (directories)
            items = items.Where(x => !(x.EndsWith("\\") || x.EndsWith("/")));

            if (Directory.Exists(tempDirectory))
            {
                Directory.Delete(tempDirectory, true);
            }

            packageReader.CopyFiles(tempDirectory, items, ExtractFile, new NullLogger(), token);

            var fullTargetDirectory = Path.GetFullPath(targetDirectory);

            IOEx.MoveDirectory(tempDirectory, fullTargetDirectory);
        }
        public static float?GetFloat(object val, bool parse, string fmt)
        {
            if (val == null)
            {
                return(null);
            }
            try {
                TypeCode tc = val.GetTypeCode();
                switch (tc)
                {
                case TypeCode.Single: return(Convert.ToSingle(val));

                case TypeCode.Double: return(DoubleToFloat(Convert.ToDouble(val)));

                case TypeCode.String:
                    if (!parse)
                    {
                        return(null);
                    }
                    float n;
                    if (!TryFromServer(Convert.ToString(val), out n, 0))
                    {
                        return(null);
                    }
                    return(n);

                default:
                    if (IsNumeric(tc))
                    {
                        return(Convert.ToSingle(val));
                    }
                    byte[] b  = val as byte[];
                    int    ix = 0;
                    if (b?.Length == sizeof(float))
                    {
                        return(IOEx.GetSingle(b, ref ix));
                    }
                    return(null);
                }
            } catch { return(null); }
        }
Esempio n. 14
0
    /// <summary>
    /// Compresses old loader log files into a zip archive.
    /// </summary>
    private static void HandleLogsAndCrashdumps()
    {
        var loaderConfig = IoC.Get <LoaderConfig>();

        // Logs (delete & compress)
        using var logCompressor = new LogFileCompressor(Paths.ArchivedLogPath);
        logCompressor.AddFiles(Paths.LogPath, TimeSpan.FromHours(loaderConfig.LogFileCompressTimeHours));
        logCompressor.DeleteOldFiles(TimeSpan.FromHours(loaderConfig.LogFileDeleteHours));

        // Crashdumps (delete)
        var dumpFolders = Directory.GetDirectories(Paths.CrashDumpPath);
        var now         = DateTime.UtcNow;

        foreach (var folder in dumpFolders)
        {
            var timeElapsed = now - Directory.GetLastWriteTimeUtc(folder);
            if (timeElapsed.TotalHours > loaderConfig.CrashDumpDeleteHours)
            {
                IOEx.TryDeleteDirectory(folder);
            }
        }
    }
        public static int?GetInt(object val, bool parse)
        {
            if (val == null)
            {
                return(null);
            }
            try {
                TypeCode tc = val.GetTypeCode();
                switch (tc)
                {
                case TypeCode.String:
                    if (!parse)
                    {
                        return(null);
                    }
                    int n;
                    if (!TryFromServer(Convert.ToString(val), out n, 0))
                    {
                        return(null);
                    }
                    return(n);

                case TypeCode.UInt32: return(unchecked ((int)(uint)val));

                default:
                    if (IsNumeric(tc))
                    {
                        return(Convert.ToInt32(val));
                    }
                    byte[] b  = val as byte[];
                    int    ix = 0;
                    if (b?.Length == sizeof(int))
                    {
                        return(IOEx.GetInt32(b, ref ix));
                    }
                    return(null);
                }
            } catch { return(null); }
        }
        public static ulong?GetULong(object val, bool parse)
        {
            if (val == null)
            {
                return(null);
            }
            try {
                TypeCode tc = val.GetTypeCode();
                switch (tc)
                {
                case TypeCode.String:
                    if (!parse)
                    {
                        return(null);
                    }
                    ulong n;
                    if (!TryFromServer(Convert.ToString(val), out n, 0))
                    {
                        return(null);
                    }
                    return(n);

                case TypeCode.Int64: return(unchecked ((ulong)(long)val));

                default:
                    if (IsNumeric(tc))
                    {
                        return(Convert.ToUInt64(val));
                    }
                    byte[] b  = val as byte[];
                    int    ix = 0;
                    if (b?.Length == sizeof(ulong))
                    {
                        return(IOEx.GetUInt64(b, ref ix));
                    }
                    return(null);
                }
            } catch { return(null); }
        }
        public static decimal?GetDecimal(object val, bool parse, string fmt)
        {
            if (val == null)
            {
                return(null);
            }
            try {
                TypeCode tc = val.GetTypeCode();
                switch (tc)
                {
                case TypeCode.Decimal: return(Convert.ToDecimal(val));

                case TypeCode.String:
                    if (!parse)
                    {
                        return(null);
                    }
                    decimal n;
                    if (!TryFromServer(Convert.ToString(val), out n, decimal.Zero))
                    {
                        return(null);
                    }
                    return(n);

                default:
                    if (IsNumeric(tc))
                    {
                        return(Convert.ToDecimal(val));
                    }
                    byte[] b  = val as byte[];
                    int    ix = 0;
                    if (b?.Length == sizeof(decimal))
                    {
                        return(IOEx.GetDecimal(b, ref ix));
                    }
                    return(null);
                }
            } catch { return(null); }
        }
        public static TimeSpan?GetTime(object val, bool parse)
        {
            if (val is TimeSpan? && IOEx.IsNullable(val))
            {
                return((TimeSpan?)val);
            }
            if (val is TimeSpan)
            {
                return((TimeSpan)val);
            }
            if (val is long)
            {
                return(new TimeSpan((long)val));
            }
            long?n = NumberEx.GetLong(val);

            if (n != null)
            {
                return((n == 0) ? TimeSpan.Zero : new TimeSpan(n.Value));
            }
            string s = parse ? val?.ToString() : null;

            if (s == null)
            {
                return((TimeSpan?)null);
            }
            TimeSpan ret;

            if (IsTimeSpan(s) && TryFromServer(s, out ret, TimeSpan.Zero))
            {
                return(ret);
            }
            if (TimeSpan.TryParse(s, out ret))
            {
                return(ret);
            }
            return(ParseTime(s));
        }
Esempio n. 19
0
        /// <summary>
        /// 备份差异项
        /// </summary>
        private bool MoveDiferrences()
        {
            int skipFile  = 0;
            int fileCount = 0;

            for (int i = 0; i < fileName.Count; i++) //循环每一个源文件
            {
                if (sameFilesIndex.Contains(i))      //如果文件索引出现在了相同文件的List上
                {
                    skipFile++;
                    continue;//跳过备份
                }
                fileCount++;
                FileInfo targetFile = new FileInfo(targetDirectory + "\\" + fullFileName[i].Replace(fileName[i], "").Replace(":", "#C#").Replace("\\", "#S#") + fileName[i]);
                try
                {
                    if (!targetFile.Directory.Exists)
                    {
                        //如果目标文件的目录不存在的话就创建一个,否则会报异常
                        targetFile.Directory.Create();
                    }
                    Thread t = new Thread(new ParameterizedThreadStart(ChangeStatusText));
                    t.Start("正在复制文件:" + fullFileName[i]);

                    //复制文件
                    File.Copy(fullFileName[i], targetFile.FullName);
                }
                catch (IOException IOEx)
                {
                    appendLog("在复制文件时发生读写异常:" + IOEx.ToString());
                    return(false);
                }
                catch (Exception ex)
                {
                    appendLog("在复制文件时发生异常:" + ex.ToString());
                    return(false);
                }
                appendLog("已复制" + fullFileName[i] + "到" + targetFile.FullName);
                winMain.CurrentFileCount = "正在复制:" + fileCount.ToString() + "/" + (fileName.Count + aloneFiles.Count - sameAloneFilesIndex.Count - sameFilesIndex.Count).ToString();
            }
            for (int i = 0; i < aloneFiles.Count; i++) //循环每一个源文件
            {
                if (sameAloneFilesIndex.Contains(i))   //如果文件索引出现在了相同文件的List上
                {
                    skipFile++;
                    continue;//跳过备份
                }
                fileCount++;
                FileInfo targetFile = new FileInfo(targetDirectory + "\\" + aloneFiles[i].FullName.Replace(aloneFiles[i].Name, "").Replace(":", "#C#").Replace("\\", "#S#") + "\\" + aloneFiles[i].Name);
                try
                {
                    if (!targetFile.Directory.Exists)
                    {
                        //如果目标文件的目录不存在的话就创建一个,否则会报异常
                        targetFile.Directory.Create();
                    }

                    Thread t = new Thread(new ParameterizedThreadStart(ChangeStatusText));
                    t.Start("正在复制文件:" + aloneFiles[i].FullName);


                    //复制文件
                    File.Copy(aloneFiles[i].FullName, targetFile.FullName);
                }
                catch (IOException IOEx)
                {
                    appendLog("在复制文件时发生读写异常:" + IOEx.ToString());
                    return(false);
                }
                catch (Exception ex)
                {
                    appendLog("在复制文件时发生异常:" + ex.ToString());
                    return(false);
                }
                appendLog("已复制" + aloneFiles[i].FullName + "到" + targetFile.FullName);
                winMain.CurrentFileCount = "正在复制:" + fileCount.ToString() + "/" + (fileName.Count + aloneFiles.Count - sameAloneFilesIndex.Count - sameFilesIndex.Count).ToString();
            }

            appendLog("备份完成,复制了" + fileCount.ToString() + "个文件");
            new Thread(new ParameterizedThreadStart(refreshWinMainTxtLog)).Start("");


            return(true);
        }
Esempio n. 20
0
        public void IOEx_BlobIO()
        {
            string[] map = new string[] { "Int", "Int", "NVarChar", "VarBinary" };
            object[] val = new object[] { 1234, IOEx.SafeIO <int>(null), "初めまして", Encoding.UTF8.GetBytes("This is a binary string") };
            BlobIO   b   = new BlobIO(map, val);

            byte[] m = b.Map;
            Assert.Equal(b.GetN <int>(0), val[0]); // Failed to get value");
            b.Set(0, 9876);
            Assert.Equal(b.GetN <int>(0), 9876);   // Failed to set value");
            b.Set(0, 9876.0);
            Assert.Equal(b.GetN <int>(0), 9876);   // Failed to set value");
            b.Clear(0);
            Assert.Equal(b.GetN <int>(0), null);   // Failed to clear value");
            b = BlobIO.Data(NumberEx.Numeric(Math.PI, out decimal? v) ? v : null);
            Assert.Equal((decimal)Math.PI, b.GetDecimal(0));
            b = BlobIO.Data(val);
            Assert.Equal(b.GetN <int>(0), val[0]);         // Failed to get value");
            Assert.Equal(b.GetN <int>(1), val[1] as int?); // Failed to get value");
            Assert.Equal(b.Get <string>(2), val[2]);       // Failed to get value");
            Assert.True(CollectionEx.ArrayEquals(b.Get <byte[]>(3), val[3] as byte[]), "Failed to get value");
            Assert.True(CollectionEx.ArrayEquals(m, b.Map), "Failed to get value");
            byte[] io;
            Assert.True(NumberEx.TryFromServerHex("0x0000000308080C001111111100111111110000000000", out io), "Failed to parse IO");
            b = new BlobIO(io);
            Assert.Null(b.PK);
            string str = b.Str;

            b.PK = 0;
            Assert.True(NumberEx.TryFromServerHex("0x000100030808000000000C001111111100111111110000000000", out io), "Failed to parse IO with PK");
            Assert.NotEqual(str, b.Str);
            Assert.Equal(0, b.PK);
            b.PK = null;
            Assert.True(NumberEx.TryFromServerHex("0x0000000308080C001111111100111111110000000000", out io), "Failed to parse IO with PK");
            Assert.Equal(str, b.Str);
            Assert.Null(b.PK);
            b.PK = -1;
            Assert.True(NumberEx.TryFromServerHex("0x0001000308080FFFFFFFFC001111111100111111110000000000", out io), "Failed to parse IO with PK");
            Assert.NotEqual(str, b.Str);
            Assert.Equal(-1, b.PK);

            b  = null;
            b += 1;
            b += (short)1;
            b += "初めまして";
            b += Math.PI;
            b += Math.PI.DoubleToFloat();
            b += IOEx.SafeIO <long>(null);
            b += (bool?)null;
            b += TestGuid;
            b += io;
            b += DateTimeEx.s_Epoch;
            string friendly = "1, 1, '初めまして', 3.142, 3.142, NULL, NULL, 'ffffffff-ffff-ffff-ffff-ffffffffffff', 'AAEAAwgID/////wAEREREQARERERAAAAAAA=', '01/01/1970 00:00:00'";
            string bstr     = "AAMACggQDAYNAAIOFSEAAAAAAQAAAQAAAAAP5Yid44KB44G+44GX44GmAEAJIftURC0YAEBJD9sBAQD/////////////////////AAAAABoAAQADCAgP/////AARERERABEREREAAAAAAAAIn3/197WAAAD/AAAABQAAAMD/";

            Assert.Null(b.PK);
            Assert.Equal(bstr, b.Str);                                                                                                                                                                            // Failed to get value");
            Assert.Equal("Int, SmallInt, NVarChar, Float, Real, BigInt, Bit, UniqueIdentifier, VarBinary, DateTime2", b.StrMap);                                                                                  // Failed to get value");
            Assert.Equal("1, 1, '初めまして', 3.1415927, 3.141593, NULL, NULL, 'ffffffff-ffff-ffff-ffff-ffffffffffff', 0x0001000308080ffffffffc001111111100111111110000000000, '1970-01-01T00:00:00.000'", b.StrData); // Failed to get value");
            Assert.Equal(friendly, b.Friendly);                                                                                                                                                                   // Failed to get value");
            b.Name = "V";
            b.Cols = "a,b,c,d,e,f,g,h,i,j".Split(',');
            Assert.Equal("a, b, c, d, e, f, g, h, i, j", b.StrCols);                                                                                                                                                                                                                                             // Failed to get value");
            Assert.Equal("\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\"", b.Select);                                                                                                                                                                                                      //, "Failed to get value");
            Assert.Equal("\"a\" = 1, \"b\" = 1, \"c\" = 0x1d5281307e3057306630, \"d\" = 3.1415927, \"e\" = 3.141593, \"f\" = NULL, \"g\" = NULL, \"h\" = 'ffffffff-ffff-ffff-ffff-ffffffffffff', \"i\" = 0x0001000308080ffffffffc001111111100111111110000000000, \"j\" = '1970-01-01T00:00:00.000'", b.Update);  //, "Failed to get value");
            Assert.Equal("\"a\" = V.GetInt32(0), \"b\" = V.GetInt16(1), \"c\" = V.GetString(2), \"d\" = V.GetDouble(3), \"e\" = V.GetSingle(4), \"f\" = V.GetInt64(5), \"g\" = V.GetBool(6), \"h\" = V.GetGuid(7), \"i\" = V.GetBytes(8), \"j\" = V.GetDateTime(9)", b.UpdateVar);                               //, "Failed to get value");
            Assert.Equal(" (\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\") VALUES (1, 1, 0x1d5281307e3057306630, 3.1415927, 3.141593, NULL, NULL, 'ffffffff-ffff-ffff-ffff-ffffffffffff', 0x0001000308080ffffffffc001111111100111111110000000000, '1970-01-01T00:00:00.000')", b.Insert); //, "Failed to get value");
            Assert.Equal(" (\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\") VALUES (V.GetInt32(0), V.GetInt16(1), V.GetString(2), V.GetDouble(3), V.GetSingle(4), V.GetInt64(5), V.GetBool(6), V.GetGuid(7), V.GetBytes(8), V.GetDateTime(9))", b.InsertVar);                              //, "Failed to get value");
            Assert.Equal("V", b.Name);                                                                                                                                                                                                                                                                           // Failed to get value");

            byte[] bio = BlobIO.ExportBlobList(b);

            b = BlobIO.Data(1, (short)1, "初めまして", Math.PI, Math.PI.DoubleToFloat(), IOEx.SafeIO <long>(null), (bool?)null, TestGuid, io, DateTimeEx.s_Epoch);
            Assert.Equal(friendly, b.Friendly);                                                                                                    // Failed to get value");
            Assert.True(b.Concat(b));
            Assert.Equal(string.Join(", ", friendly, friendly), b.Friendly);                                                                       // Failed to get value");
            b = new BlobIO(bio);
            Assert.Equal(friendly, b.Friendly);                                                                                                    // Failed to get value");
            Assert.True(b.Set(4, BlobIO.Data(float.NaN, 0L, false, Guid.Empty, (byte[])null)));
            Assert.Equal("1, 1, '初めまして', 3.142, NULL, 0, False, '00000000-0000-0000-0000-000000000000', NULL, '01/01/1970 00:00:00'", b.Friendly); // Failed to get value");

            b  = new BlobIO(bio);
            io = b.IO;
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList();
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            int ix = 0;

            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(--ix, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io.Take(pair.Value.Length)));
            }
            byte[] dataio, prefixio, suffixio, ixsio, sbioio;
            string data = "0000000001000001000000000fe5889de38281e381bee38197e381a600400921fb54442d180040490fdb010100ffffffffffffffffffffffffffffffff000000001a0001000308080ffffffffc00111111110011111111000000000000089f7ff5f7b5800000";

            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + data, out dataio) ? dataio : null, b.DataIO));
            string prefix = "0x0003000a08100c060d00020e1521";

            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(prefix, out prefixio) ? prefixio : null, b.PrefixIO));
            string presuffix = "ff000a016101620163016401650166016701680169016a00";
            string suffix    = presuffix + "05000000c0ff";

            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));
            string ixs = "0002" + "00000066" + "000000cc";

            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            string sio  = prefix + data + suffix;
            string sbio = sio + ixs + data + data + data;

            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");

            b = new BlobIO(bstr);
            Assert.Equal(friendly, b.Friendly); // Failed to get value");

            b.PK = 0;
            Assert.Equal(0, b.PK);
            Assert.Equal("AQMAAAAAAAoIEAwGDQACDhUhAAAAAAEAAAEAAAAAD+WIneOCgeOBvuOBl+OBpgBACSH7VEQtGABASQ/bAQEA/////////////////////wAAAAAaAAEAAwgID/////wAEREREQARERERAAAAAAAACJ9/9fe1gAAA/wAAAAUAAADA/w==", b.Str); // Failed to get value");
            Assert.Equal("Int, SmallInt, NVarChar, Float, Real, BigInt, Bit, UniqueIdentifier, VarBinary, DateTime2", b.StrMap);                                                                                     // Failed to get value");
            Assert.Equal("1, 1, '初めまして', 3.1415927, 3.141593, NULL, NULL, 'ffffffff-ffff-ffff-ffff-ffffffffffff', 0x0001000308080ffffffffc001111111100111111110000000000, '1970-01-01T00:00:00.000'", b.StrData);    // Failed to get value");
            Assert.Equal(friendly, b.Friendly);                                                                                                                                                                      // Failed to get value");
            b.Name = "V";
            b.Cols = "a,b,c,d,e,f,g,h,i,j".Split(',');
            Assert.Equal("a, b, c, d, e, f, g, h, i, j", b.StrCols);                                                                                                                                                                                                                                             // Failed to get value");
            Assert.Equal("\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\"", b.Select);                                                                                                                                                                                                      //, "Failed to get value");
            Assert.Equal("\"a\" = 1, \"b\" = 1, \"c\" = 0x1d5281307e3057306630, \"d\" = 3.1415927, \"e\" = 3.141593, \"f\" = NULL, \"g\" = NULL, \"h\" = 'ffffffff-ffff-ffff-ffff-ffffffffffff', \"i\" = 0x0001000308080ffffffffc001111111100111111110000000000, \"j\" = '1970-01-01T00:00:00.000'", b.Update);  //, "Failed to get value");
            Assert.Equal("\"a\" = V.GetInt32(0), \"b\" = V.GetInt16(1), \"c\" = V.GetString(2), \"d\" = V.GetDouble(3), \"e\" = V.GetSingle(4), \"f\" = V.GetInt64(5), \"g\" = V.GetBool(6), \"h\" = V.GetGuid(7), \"i\" = V.GetBytes(8), \"j\" = V.GetDateTime(9)", b.UpdateVar);                               //, "Failed to get value");
            Assert.Equal(" (\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\") VALUES (1, 1, 0x1d5281307e3057306630, 3.1415927, 3.141593, NULL, NULL, 'ffffffff-ffff-ffff-ffff-ffffffffffff', 0x0001000308080ffffffffc001111111100111111110000000000, '1970-01-01T00:00:00.000')", b.Insert); //, "Failed to get value");
            Assert.Equal(" (\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\") VALUES (V.GetInt32(0), V.GetInt16(1), V.GetString(2), V.GetDouble(3), V.GetSingle(4), V.GetInt64(5), V.GetBool(6), V.GetGuid(7), V.GetBytes(8), V.GetDateTime(9))", b.InsertVar);                              //, "Failed to get value");
            Assert.Equal("V", b.Name);                                                                                                                                                                                                                                                                           // Failed to get value");

            int seed = 0;

            io  = b.Export(false, ref seed);
            bio = BlobIO.ExportBlobList(false, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(false);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(false, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            ix = 0;
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(--ix, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io.Take(pair.Value.Length)));
            }
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + data, out dataio) ? dataio : null, b.DataIO));
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(prefix, out prefixio) ? prefixio : null, b.PrefixIO));
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");


            Assert.Equal(io.Length + sizeof(int), b.IO.Length);
            io  = b.IO;
            bio = BlobIO.ExportBlobList(true, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(true);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(true, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            io = b.PrefixIO.Concat(b.DataIO).ToArray();
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(0, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io));
            }
            ixs = "0002" + "0000006a" + "000000d4";
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            prefix = "0x0103" + "00000000" + "000a08100c060d00020e1521";
            sio    = prefix + data + suffix;
            sbio   = sio + ixs + "00000000" + data + "00000000" + data + "00000000" + data;
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");


            b    = new BlobIO(bstr);
            b.PK = -1;
            Assert.Equal(-1, b.PK);

            io  = b.IO;
            bio = BlobIO.ExportBlobList(true, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(true);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(true, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            io = b.PrefixIO.Concat(b.DataIO).ToArray();
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(-1, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io));
            }
            ixs = "0002" + "0000006a" + "000000d4";
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            prefix = "0x0103" + "FFFFFFFF" + "000a08100c060d00020e1521";
            sio    = prefix + data + "ff00000005000000c0ff";
            sbio   = sio + ixs + "FFFFFFFF" + data + "FFFFFFFF" + data + "FFFFFFFF" + data;
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");


            b.Name = "V";
            b.Cols = "a,b,c,d,e,f,g,h,i,j".Split(',');
            io     = b.IO;
            bio    = BlobIO.ExportBlobList(true, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(true);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(true, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            io = b.PrefixIO.Concat(b.DataIO).ToArray();
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(-1, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io));
            }
            ixs = "0002" + "0000006a" + "000000d4";
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            prefix = "0x0103" + "FFFFFFFF" + "000a08100c060d00020e1521";
            sio    = prefix + data + suffix;
            sbio   = sio + ixs + "FFFFFFFF" + data + "FFFFFFFF" + data + "FFFFFFFF" + data;
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");



            b.PK = null;
            Assert.Null(b.PK);

            seed = 0;
            io   = b.Export(true, ref seed);
            bio  = BlobIO.ExportBlobList(true, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(true);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(true, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            io = b.PrefixIO.Concat(b.DataIO).ToArray();
            ix = 0;
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(--ix, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io));
            }
            ixs = "0002" + "0000006a" + "000000d4";
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            prefix = "0x0103" + "FFFFFFFF" + "000a08100c060d00020e1521";
            sio    = prefix + data + suffix;
            sbio   = sio + ixs + "FFFFFFFE" + data + "FFFFFFFD" + data + "FFFFFFFC" + data;
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");



            b.PK = null;
            Assert.Null(b.PK);
            b.Indexes = new int[] { 1, 3, 5 };
            Assert.Equal("1,3,5", b.StrIxs); // Failed to get indexes");
            Assert.Null(b.StrNulls);         // Failed to get null oks");
            Assert.Null(b.StrOuts);          // Failed to get outputs");

            seed = 0;
            io   = b.Export(true, ref seed);
            bio  = BlobIO.ExportBlobList(true, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(true);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(true, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            io = b.PrefixIO.Concat(b.DataIO).ToArray();
            ix = 0;
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(--ix, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io));
            }
            ixs = "0002" + "0000006a" + "000000d4";
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            prefix = "0x0103" + "FFFFFFFF" + "000a08100c060d00020e1521";
            suffix = presuffix + "052a0000c0ff";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));
            sio  = prefix + data + suffix;
            sbio = sio + ixs + "FFFFFFFE" + data + "FFFFFFFD" + data + "FFFFFFFC" + data;
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");

            b.Indexes = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrIxs); // Failed to get indexes");
            Assert.Null(b.StrNulls);                       // Failed to get null oks");
            Assert.Null(b.StrOuts);                        // Failed to get outputs");
            suffix = presuffix + "05ff0300c0ff";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Indexes = new int[] { 0, 24 };
            Assert.Equal("0", b.StrIxs); // Failed to get indexes");
            Assert.Null(b.StrNulls);     // Failed to get null oks");
            Assert.Null(b.StrOuts);      // Failed to get outputs");
            suffix = presuffix + "05010000c0ff";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Indexes = new int[] { 0 };
            Assert.Equal("0", b.StrIxs); // Failed to get indexes");
            Assert.Null(b.StrNulls);     // Failed to get null oks");
            Assert.Null(b.StrOuts);      // Failed to get outputs");
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Indexes = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            b.Nulls   = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            b.Outs    = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            b.Ins     = new int[] { 6 };
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrIxs);   // Failed to get indexes");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrNulls); // Failed to get null oks");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrOuts);  // Failed to get outputs");
            suffix = presuffix + "05ffffff3f10";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Indexes = null;
            b.Nulls   = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            b.Outs    = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            Assert.Null(b.StrIxs);                           // Failed to get indexes");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrNulls); // Failed to get null oks");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrOuts);  // Failed to get outputs");
            suffix = presuffix + "0500fcff3f10";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Nulls = null;
            b.Outs  = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            Assert.Null(b.StrIxs);                          // Failed to get indexes");
            Assert.Null(b.StrNulls);                        // Failed to get null oks");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrOuts); // Failed to get outputs");
            suffix = presuffix + "050000f03f10";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Nulls = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            b.Outs  = null;
            Assert.Null(b.StrIxs);                           // Failed to get indexes");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrNulls); // Failed to get null oks");
            Assert.Null(b.StrOuts);                          // Failed to get outputs");
            suffix = presuffix + "0500fc0f0010";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            Assert.True(NumberEx.TryFromServerHex("0x0100" + "FFFFFFFF" + "000a08100c060d00020e1521" + data +
                                                  presuffix +
                                                  ixs + "FFFFFFFE" + data + "FFFFFFFD" + data + "FFFFFFFC" + data, out bio));
            ix = 0;
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(--ix, pair.Key);
            }
        }
    public async Task InstallReloadedAsync(string?installFolder = null, bool createShortcut = true, bool startReloaded = true)
    {
        // Step
        installFolder ??= Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "Reloaded-II");
        Directory.CreateDirectory(installFolder);

        using var tempDownloadDir = new TemporaryFolderAllocation();
        var progressSlicer = new ProgressSlicer(new Progress <double>(d =>
        {
            Progress = d * 100.0;
        }));

        try
        {
            var downloadLocation = Path.Combine(tempDownloadDir.FolderPath, $"Reloaded-II.zip");

            // 0.15
            CurrentStepNo = 0;
            await DownloadReloadedAsync(downloadLocation, progressSlicer.Slice(0.15));

            if (CancellationToken.IsCancellationRequested)
            {
                throw new TaskCanceledException();
            }

            // 0.20
            CurrentStepNo = 1;
            await ExtractReloadedAsync(installFolder, downloadLocation, progressSlicer.Slice(0.05));

            if (CancellationToken.IsCancellationRequested)
            {
                throw new TaskCanceledException();
            }

            // 1.00
            CurrentStepNo = 2;
            await CheckAndInstallMissingRuntimesAsync(installFolder, tempDownloadDir.FolderPath,
                                                      progressSlicer.Slice(0.8),
                                                      s => { CurrentStepDescription = s; }, CancellationToken.Token);

            var executableName = IntPtr.Size == 8 ? "Reloaded-II.exe" : "Reloaded-II32.exe";
            var executablePath = Path.Combine(installFolder, executableName);
            var shortcutPath   = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "Reloaded-II.lnk");

            if (createShortcut)
            {
                CurrentStepDescription = "Creating Shortcut";
                MakeShortcut(shortcutPath, executablePath);
            }

            CurrentStepDescription = "All Set";

            if (startReloaded)
            {
                Process.Start(executablePath);
            }
        }
        catch (TaskCanceledException)
        {
            IOEx.TryDeleteDirectory(installFolder);
        }
        catch (Exception e)
        {
            IOEx.TryDeleteDirectory(installFolder);
            MessageBox.Show("There was an error in installing Reloaded.\n" +
                            $"Feel free to open an issue on github.com/Reloaded-Project/Reloaded-II if you require support.\n" +
                            $"Message: {e.Message}\n" +
                            $"Stack Trace: {e.StackTrace}", "Error in Installing Reloaded");
        }
    }
    /// <summary>
    /// Creates the mod.
    /// </summary>
    /// <param name="showNonUniqueWindow">Shows a message to tell the user the mod isn't unique.</param>
    public async Task <PathTuple <ModConfig>?> CreateMod(Action showNonUniqueWindow)
    {
        if (!IsUnique(showNonUniqueWindow))
        {
            return(null);
        }

        var config = new ModConfig()
        {
            ModId = ModId,
            ReleaseMetadataFileName = $"{ModId}.ReleaseMetadata.json"
        };

        var modDirectory = Path.Combine(IoC.Get <LoaderConfig>().GetModConfigDirectory(), IOEx.ForceValidFilePath(ModId));
        var filePath     = Path.Combine(modDirectory, ModConfig.ConfigFileName);
        await IConfig <ModConfig> .ToPathAsync(config, filePath);

        return(new PathTuple <ModConfig>(filePath, config));
    }
        public static DateTimeOffset?GetDate(object val, bool parse, bool isutc)
        {
            if (val is TimeSpan?)
            {
                return((isutc ? new DateTimeOffset(DateTime.Today.Ticks, TimeSpan.Zero) : new DateTimeOffset(DateTime.Today)) + ((TimeSpan?)val ?? TimeSpan.Zero));
            }
            if (val is TimeSpan)
            {
                return(DateTimeOffset.MinValue + (TimeSpan)val);
            }
            if (val is DateTimeOffset? && IOEx.IsNullable(val))
            {
                return((DateTimeOffset?)val);
            }
            if (val is DateTimeOffset)
            {
                return((DateTimeOffset)val);
            }
            if (val is DateTime? && IOEx.IsNullable(val))
            {
                DateTime?dt = (DateTime?)val;
                if (dt == null)
                {
                    return(null);
                }
                if (dt.Value <= DateTime.MinValue.AddHours(14))
                {
                    return(DateTimeOffset.MinValue);
                }
                if (dt.Value >= DateTime.MaxValue.AddHours(-14))
                {
                    return(DateTimeOffset.MaxValue);
                }
                return(isutc ? new DateTimeOffset(dt.Value.Ticks, TimeSpan.Zero) : new DateTimeOffset(dt.Value));
            }
            if (val is DateTime)
            {
                DateTime dt = (DateTime)val;
                if (dt <= DateTime.MinValue.AddHours(14))
                {
                    return(DateTimeOffset.MinValue);
                }
                if (dt >= DateTime.MaxValue.AddHours(-14))
                {
                    return(DateTimeOffset.MaxValue);
                }
                return(isutc ? new DateTimeOffset(dt.Ticks, TimeSpan.Zero) : new DateTimeOffset(dt));
            }
            string s = parse ? val?.ToString() : null;

            if (s == null)
            {
                return(null);
            }
            DateTimeOffset ret;

            if (IsRoundtripDate(s) && TryFromServerRoundtrip(s, out ret, DateTimeOffset.MinValue))
            {
                return(ret);                                                                                   // is roundtrip date
            }
            if (IsIso8601Date(s) && ((isutc && TryFromServer(s, out ret, DateTimeOffset.MinValue)) || (!isutc && TryFromServerLocal(s, DateTimeOffset.Now.Offset.Hours, out ret, DateTimeOffset.MinValue))))
            {
                return(ret);                                                                                                                                                                                             // is iso 8601 date
            }
            if (IsIso8601DateOnly(s) && TryFromServerDate(s, out ret, DateTimeOffset.MinValue))
            {
                return(ret);                                                                                // is iso 8601 date only
            }
            if (DateTimeOffset.TryParse(s, null, isutc ? DateTimeStyles.AssumeUniversal : DateTimeStyles.AssumeLocal, out ret))
            {
                return(ret);                                                                                                                // is formatted date
            }
            return(null);
        }
Esempio n. 24
0
 //Saves List<Member> to file in disk
 public void Save(List <Member> memberList)
 {
     try
     {
         //using (FileStream fileStream = new FileStream(@"\db.bin", FileMode.Create))
         using (Stream stream = File.Open(filePath, FileMode.Create))
         {
             var formatter = new BinaryFormatter();
             formatter.Serialize(stream, memberList);
         }
     }
     catch (IOException IOEx)
     {
         throw new ApplicationException("Error! Can't write to file. Message: " + IOEx.ToString());
     }
 }