ensureSafePath static method

String ensureSafePath(
  1. String filePath
)

指定されたパスが長すぎる場合、Windows上で長いパスサポートを追加します filePath 処理するファイルパス return 長いパスをサポートするために修正されたパス、または元のパス

Implementation

static String ensureSafePath(String filePath) {
  if (!Platform.isWindows) {
    return filePath; // Windowsでない場合は修正不要
  }

  // すでにプレフィックスが付いている場合はそのまま返す
  if (filePath.startsWith(_longPathPrefix)) {
    return filePath;
  }

  // 絶対パスでない場合は絶対パスに変換
  final absolutePath = p.isAbsolute(filePath)
      ? filePath
      : p.absolute(filePath);

  // パスの長さがWindows制限を超える場合
  if (absolutePath.length > _windowsPathLengthLimit) {
    debugPrint('Path length exceeds Windows limit, using long path: $absolutePath');
    return '$_longPathPrefix${absolutePath.replaceAll('/', '\\')}';
  }

  return absolutePath;
}