public long SaveToFile(string filePath)
    {
        string backupPath = filePath + ".bak";

        try
        {
            if (Lfs.IsFileExists(filePath))
            {
                Lfs.CopyFile(filePath, backupPath);
            }
        }
        catch (Exception ex)
        {
            ex._Error();
        }

        return(Lfs.WriteJsonToFile(filePath, this, flags: FileFlags.AutoCreateDirectory | FileFlags.OnCreateSetCompressionFlag));
    }
Example #2
0
    // UNIX におけるコマンド名からフルパスを取得する (指定されたファイル名がフルパスとして見つからない場合)
    public string UnixGetFullPathFromCommandName(string commandName)
    {
        if (Env.IsUnix == false)
        {
            throw new ArgumentException("Env.IsUnix == false");
        }
        if (commandName._IsEmpty())
        {
            throw new ArgumentException(nameof(commandName));
        }

        commandName = commandName.Trim();

        if (this.PathParser.IsAbsolutePath(commandName))
        {
            if (Lfs.IsFileExists(commandName))
            {
                // 最初から指定されたフルパスが存在する
                return(commandName);
            }

            // 指定されたフルパスにファイルが存在しない。コマンド名だけを取り出して解決しようと試みる。
            commandName = this.PathParser.GetFileName(commandName);
        }

        lock (CommandNamdToFullPathCache)
        {
            return(CommandNamdToFullPathCache._GetOrNew(commandName, () =>
            {
                string fullPath = UnixGetFullPathFromCommandNameInternal(commandName);

                if (fullPath._IsEmpty())
                {
                    throw new CoresException($"The full path of UNIX command '{commandName}' not found.");
                }

                return fullPath;
            }));
        }
    }
    protected override void InitImpl(object?param = null)
    {
        // sensors コマンドが利用可能かどうか確認
        if (EasyExec.ExecAsync(Consts.LinuxCommands.Sensors, "-u")._TryGetResult() != default)
        {
            IsSensorsCommandOk = true;
        }

        // /sys/class/thermal/ から取得可能な値一覧を列挙
        FileSystemEntity[]? dirList = null;
        try
        {
            dirList = Lfs.EnumDirectory(Consts.LinuxPaths.SysThermal);
        }
        catch { }

        if (dirList != null)
        {
            foreach (var dir in dirList)
            {
                string fileName = Lfs.PathParser.Combine(dir.FullPath, "temp");

                if (Lfs.IsFileExists(fileName))
                {
                    try
                    {
                        Lfs.ReadStringFromFile(fileName);

                        ThermalFiles.Add(dir.Name, fileName);
                    }
                    catch
                    {
                    }
                }
            }
        }
    }
 protected override void InitImpl(object?param = null)
 {
     isBirdcExists  = Lfs.IsFileExists(Consts.LinuxCommands.Birdc);
     isBirdc6Exists = Lfs.IsFileExists(Consts.LinuxCommands.Birdc6);
 }