changeLinuxAppName method

Future<File?> changeLinuxAppName(
  1. String? appName
)

Implementation

Future<File?> changeLinuxAppName(String? appName) async {
  List? contentLineByLine = await readFileAsLineByline(
    filePath: linuxCMakeListsPath,
  );
  if (checkFileExists(contentLineByLine)) {
    logger.w('''
    Linux AppName could not be changed because,
    The related file could not be found in that path:  $linuxCMakeListsPath
    ''');
    return null;
  }
  String? oldAppName;
  for (var i = 0; i < contentLineByLine!.length; i++) {
    if (contentLineByLine[i].startsWith('set(BINARY_NAME')) {
      oldAppName = RegExp(r'set\(BINARY_NAME "(\w+)"\)')
          .firstMatch(contentLineByLine[i])
          ?.group(1);
      contentLineByLine[i] = 'set(BINARY_NAME \"$appName\")';
      break;
    }
  }
  var writtenFile = await writeFile(
    filePath: linuxCMakeListsPath,
    content: contentLineByLine.join('\n'),
  );
  if (oldAppName != null) {
    if (await changeLinuxCppName(appName, oldAppName) == false) {
      return null;
    }
  }
  logger.i('Linux appname changed successfully to : $appName');
  return writtenFile;
}