GetFileSize() public static method

public static GetFileSize ( FileSizeUnitType sizeType, long size ) : float
sizeType FileSizeUnitType
size long
return float
Esempio n. 1
0
    public static void GenerateScriptVersionContent(out UpdateModuleMessage assetBundle)
    {
        assetBundle = new UpdateModuleMessage();
        int assetSize = 0;

        string        generate = "\tScripts = {\n";
        List <string> fileList = new List <string>();

        GetAllScriptFile(Application.dataPath + "/Resources" + SCRIPT_PATH, fileList);

        for (int i = 0; i < fileList.Count; ++i)
        {
            //TODO:加密每一个script文件,并拷贝到PersistentDataPath
            var    file        = fileList[i];
            byte[] fileContent = null;
            FileManager.LoadFileWithBytes(file, out fileContent);
            var size = FileManager.GetFileSize(FileSizeUnitType.Type_Kb, fileContent.Length);
            generate  += "\t\t{\n";
            generate  += "\t\t\tname=\"" + file.Replace(Application.dataPath + "/Resources/", "") + "\"" + ",\n";
            generate  += "\t\t\tsize=" + Mathf.Ceil(size) + ",\n";
            generate  += "\t\t},\n";
            assetSize += (int)Mathf.Ceil(size);
        }

        generate           += "\t},\n";
        assetBundle.Content = generate;
        assetBundle.Size    = assetSize;
    }
Esempio n. 2
0
        public void FileManager_GetFileSize_Failed()
        {
            string       validVersion = "–v,--v,/v,--version,";
            string       validSize    = "–s, --s, /s, --size,";
            IFileManager fileManager  = new FileManager(validVersion, validSize);
            string       para1        = "trigger exception";
            string       actual       = fileManager.GetFileSize(para1, "c:/test.txt");
            string       expected     = "Invalid parameter. Paramemter shoul be one from the list " + validSize.Substring(0, validSize.Length - 1);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 3
0
 public DriveInformation(DriveInfo drive)
 {
     DriveIcon       = FolderManager.GetImageSource(drive.RootDirectory.FullName, new Size(300, 300), ItemState.Undefined);
     Name            = drive.Name;
     Format          = drive.DriveFormat;
     Type            = drive.DriveType.ToString();
     TotalFreeSpace  = drive.TotalFreeSpace;
     TotalSize       = drive.TotalSize;
     UsedSpace       = drive.TotalSize - drive.TotalFreeSpace;
     UsagePercentage = 100 - (int)Math.Round((double)drive.TotalFreeSpace / (double)drive.TotalSize * 100);
     Information     = $"{Name} ({Format}, {Type})\r\n" +
                       $" * Total Space : {FileManager.GetFileSize(TotalSize)}\r\n" +
                       $" * Free Space : {FileManager.GetFileSize(TotalFreeSpace)}\r\n" +
                       $" * Used Space : {FileManager.GetFileSize(UsedSpace)} ({UsagePercentage}%)";
 }
Esempio n. 4
0
 static public int GetFileSize_s(IntPtr l)
 {
     try {
         FileSizeUnitType a1;
         checkEnum(l, 1, out a1);
         System.Int64 a2;
         checkType(l, 2, out a2);
         var ret = FileManager.GetFileSize(a1, a2);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Esempio n. 5
0
    static void GenerateAssetBundleVersionContent(out UpdateModuleMessage assetModule)
    {
        assetModule = new UpdateModuleMessage();

        InitAssetBundleDict();
        string content    = "";
        int    moduleSize = 0;

        content += "\tPrefabs = {\n";
        foreach (KeyValuePair <string, AssetBundleRequest> obj in _assetBundleDict)
        {
            var fullPath = UpdateManager.UpdateTest + "/" + obj.Key;
            content += "\t\t{\n";
            content += "\t\t\tname=\"" + obj.Key + "\",\n";
            var asset = new FileInfo(fullPath);
            content    += "\t\t\tsize=" + Mathf.Ceil(FileManager.GetFileSize(FileSizeUnitType.Type_Kb, asset.Length)) + ",\n";
            content    += "\t\t},\n";
            moduleSize += (int)Mathf.Ceil(FileManager.GetFileSize(FileSizeUnitType.Type_Kb, asset.Length));
        }
        content            += "\t},\n";
        assetModule.Content = content;
        assetModule.Size    = moduleSize;
    }
Esempio n. 6
0
        public void FileManager_GetFileSize_Valid()
        {
            string[]     args         = { "-v", "-s", "c:/test.txt", "trigger invalid" };
            string       validVersion = "–v,--v,/v,--version,";
            string       validSize    = "–s, --s, /s, --size,";
            IFileManager fileManager  = new FileManager(validVersion, validSize);
            string       failedMsg    = "Invalid parameter. Paramemter shoul be one from the list " + validSize.Substring(0, validSize.Length - 1);

            string[] arrValidVersion = { "–s", "--s", "/s", "--size" };
            int      actual          = 0;

            foreach (var para in arrValidVersion)
            {
                if (failedMsg != fileManager.GetFileSize(para, "c:/test.txt"))
                {
                    actual++;
                }
            }

            int expected = arrValidVersion.Length;

            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// Invoke the method specified by the
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </summary>
        /// <param name="message">
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </param>
        internal async override void InvokeAsync(JSMessage message)
        {
            string callbackId = message.CallbackId;

            try
            {
                // Variables
                SqliteConnection connection;
                DBConfig         dbConfig;
                DbTransaction    transaction;
                string           connectionId, query, queryId;
                long             dbSize;
                JObject          o;

                switch (message.Method)
                {
                case "openDatabase":

                    string    dbName     = message.Args[0] as string;
                    Int64     dblevel    = (Int64)message.Args[1];
                    FileLevel level      = (FileLevel)dblevel;
                    Int64     version    = (Int64)message.Args[2];
                    float     dbVersion  = (float)version;
                    string    dbPassword = message.Args[3] as string;
                    string    dbPath     = null;
                    if (dbName.Equals(Mowbly.GetProperty <string>(Constants.PROPERTY_LOGS_DB)))
                    {
                        dbPath = Mowbly.LogDatabaseFile;
                        if (!FileManager.FileExists(dbPath))
                        {
                            FileManager.CreateFile(dbPath);
                        }
                    }
                    else
                    {
                        dbPath = FileManager.GetAbsolutePath(new FilePath
                        {
                            Path        = Path.Combine(Constants.DIR_DB, String.Concat(dbName, dbVersion.ToString())),
                            Level       = level,
                            StorageType = StorageType.Internal
                        });
                    }

                    dbSize = FileManager.GetFileSize(dbPath);

                    // Create new connection
                    try
                    {
                        connection = new SqliteConnection();
                        connection.ConnectionString = DBUtils.GetConnectionString(dbPath, dbPassword);
                        connection.Open();
                        connectionId = Guid.NewGuid().ToString();
                        dbConfigDict.Add(connectionId, new DBConfig
                        {
                            DBName     = dbName,
                            DBVersion  = dbVersion,
                            DBPath     = dbPath,
                            DBPassword = dbPassword,
                            Connection = connection
                        });

                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = connectionId
                        });
                    }
                    catch (SqliteException se)
                    {
                        string error = String.Concat(Mowbly.GetString(Constants.STRING_DATABASE_OPEN_ERROR), se.Message);
                        Logger.Error(error);
                        JToken  opt = message.Args[0] as JToken;
                        string  Id  = opt["queryId"].ToObject <string>();
                        JObject obj = new JObject();
                        obj.Add("queryId", Id);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = obj,
                            Error  = new MethodError
                            {
                                Message = error
                            }
                        });
                    }

                    break;

                case "executeQuery":

                    // Get connection id
                    JToken options = message.Args[0] as JToken;
                    connectionId = options["id"].ToObject <string>();
                    dbConfig     = dbConfigDict[connectionId];

                    // Read args
                    queryId = options["queryId"].ToObject <string>();
                    query   = options["sql"].ToObject <string>().Trim();
                    List <object> queryParams = options["params"].ToObject <List <object> >();

                    // Execute query
                    try
                    {
                        JArray data         = null;
                        int    rowsAffected = 0;
                        connection = dbConfig.Connection;

                        // Throw exception is connection is null
                        if (connection == null)
                        {
                            throw new ArgumentException(Mowbly.GetString(Constants.STRING_DATABASE_NO_CONNECTION_OPEN_ERROR));
                        }

                        // Execute query
                        if (query.ToLower().StartsWith("select"))
                        {
                            data = ProcessSelectQuery(ref connection, query, queryParams);
                        }
                        else
                        {
                            rowsAffected = ProcessNonQuery(ref connection, query, queryParams);
                        }

                        // Create result
                        o = new JObject();
                        o.Add("queryId", queryId);

                        JObject d = new JObject();
                        d.Add("rowsAffected", rowsAffected);
                        d.Add("insertId", connection.LastInsertRowId);
                        d.Add("rows", data);
                        o.Add("data", d);

                        // Notify JS
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = o
                        });
                    }
                    catch (SqliteException se)
                    {
                        // Error
                        string error = String.Concat(Mowbly.GetString(Constants.STRING_DATABASE_QUERY_ERROR), se.Message);
                        Logger.Error(error);

                        // Create result
                        o = new JObject();
                        o.Add("queryId", queryId);

                        // Notify Js
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = o,
                            Error  = new MethodError
                            {
                                Message = error
                            }
                        });
                    }

                    break;

                case "beginTransaction":

                    connectionId = message.Args[0] as string;
                    dbConfig     = dbConfigDict[connectionId];

                    // Begin transaction
                    try
                    {
                        connection = dbConfig.Connection;
                        // Throw exception is connection is null
                        if (connection == null)
                        {
                            throw new ArgumentException(Mowbly.GetString(Constants.STRING_DATABASE_NO_CONNECTION_OPEN_ERROR));
                        }

                        transaction          = connection.BeginTransaction();
                        dbConfig.Transaction = transaction;

                        // Notify JS
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = true
                        });
                    }
                    catch (SqliteException se)
                    {
                        // Error; Notify JS
                        string error = String.Concat(Mowbly.GetString(Constants.STRING_DATABASE_TRANSACTION_ERROR), se.Message);
                        Logger.Error(error);
                        JToken  opt = message.Args[0] as JToken;
                        string  Id  = opt["queryId"].ToObject <string>();
                        JObject obj = new JObject();
                        obj.Add("queryId", Id);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = obj,
                            Error  = new MethodError
                            {
                                Message = error
                            }
                        });
                    }

                    break;

                case "commit":

                    connectionId = message.Args[0] as string;
                    dbConfig     = dbConfigDict[connectionId];

                    // Commit transaction
                    try
                    {
                        transaction = dbConfig.Transaction;
                        // Throw exception is transaction is null
                        if (transaction == null)
                        {
                            throw new ArgumentException(Mowbly.GetString(Constants.STRING_DATABASE_NO_TRANSACTION_ACTIVE_ERROR));
                        }
                        transaction.Commit();

                        queryId      = message.Args[1] as string;
                        o            = new JObject();
                        o["queryId"] = queryId;
                        o["data"]    = true;

                        // Notify JS
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = o
                        });
                    }
                    catch (SqliteException se)
                    {
                        // Error; Notify JS
                        string error = String.Concat(Mowbly.GetString(Constants.STRING_DATABASE_TRANSACTION_ERROR), se.Message);
                        Logger.Error(error);
                        JToken  opt = message.Args[0] as JToken;
                        string  Id  = opt["queryId"].ToObject <string>();
                        JObject obj = new JObject();
                        obj.Add("queryId", Id);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = obj,
                            Error  = new MethodError
                            {
                                Message = error
                            }
                        });
                    }

                    break;

                case "rollback":

                    connectionId = message.Args[0] as string;
                    dbConfig     = dbConfigDict[connectionId];

                    // Commit transaction
                    try
                    {
                        transaction = dbConfig.Transaction;
                        transaction.Rollback();

                        queryId      = message.Args[1] as string;
                        o            = new JObject();
                        o["queryId"] = queryId;
                        o["data"]    = true;

                        // Notify JS
                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = o
                        });
                    }
                    catch (SqliteException se)
                    {
                        // Error; Notify JS
                        string error = String.Concat(Mowbly.GetString(Constants.STRING_DATABASE_TRANSACTION_ERROR), se.Message);
                        Logger.Error(error);
                        JToken  opt = message.Args[0] as JToken;
                        string  Id  = opt["queryId"].ToObject <string>();
                        JObject obj = new JObject();
                        obj.Add("queryId", Id);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code   = MethodResult.FAILURE_CODE,
                            Result = obj,
                            Error  = new MethodError
                            {
                                Message = error
                            }
                        });
                    }

                    break;

                default:
                    Logger.Error("Feature " + Name + " does not support method " + message.Method);
                    break;
                }
            }
            catch (Exception e)
            {
                // Error; Notify JS
                string error = String.Concat(Mowbly.GetString(Constants.STRING_DATABASE_OPERATION_ERROR), e.Message);
                Logger.Error(error);
                JToken  opt = message.Args[0] as JToken;
                string  Id  = opt["queryId"].ToObject <string>();
                JObject obj = new JObject();
                obj.Add("queryId", Id);
                InvokeCallbackJavascript(callbackId, new MethodResult
                {
                    Code   = MethodResult.FAILURE_CODE,
                    Result = obj,
                    Error  = new MethodError
                    {
                        Message = error
                    }
                });
            }
            await Task.FromResult(0);
        }