Skip to content

Commit

Permalink
Merge branch master into ai-secondary-skills
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-derevenetz committed Jul 24, 2024
2 parents aad6127 + 0c44fd0 commit 38c5915
Show file tree
Hide file tree
Showing 311 changed files with 36,032 additions and 20,447 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr_author_auto_assign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:
run:
shell: bash
steps:
- uses: toshimaru/auto-author-assign@v2.1.0
- uses: toshimaru/auto-author-assign@v2.1.1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
bash script/android/install_packages.sh
sudo apt-get -y update
sudo apt-get -y install libsdl2-dev libsdl2-mixer-dev libsdl2-image-dev
- uses: SonarSource/sonarcloud-github-c-cpp@v2
- uses: SonarSource/sonarcloud-github-c-cpp@v3
- name: Prepare SonarCloud cfamily cache
uses: actions/cache@v4
with:
Expand Down
64 changes: 28 additions & 36 deletions VisualStudio/fheroes2/sources.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@
<ClCompile Include="src\fheroes2\agg\m82.cpp" />
<ClCompile Include="src\fheroes2\agg\mus.cpp" />
<ClCompile Include="src\fheroes2\agg\xmi.cpp" />
<ClCompile Include="src\fheroes2\ai\ai_base.cpp" />
<ClCompile Include="src\fheroes2\ai\ai_battle.cpp" />
<ClCompile Include="src\fheroes2\ai\ai_battle_spell.cpp" />
<ClCompile Include="src\fheroes2\ai\ai_common.cpp" />
<ClCompile Include="src\fheroes2\ai\ai_hero_action.cpp" />
<ClCompile Include="src\fheroes2\ai\ai_personality.cpp" />
<ClCompile Include="src\fheroes2\ai\normal\ai_normal.cpp" />
<ClCompile Include="src\fheroes2\ai\normal\ai_normal_battle.cpp" />
<ClCompile Include="src\fheroes2\ai\normal\ai_normal_castle.cpp" />
<ClCompile Include="src\fheroes2\ai\normal\ai_normal_hero.cpp" />
<ClCompile Include="src\fheroes2\ai\normal\ai_normal_kingdom.cpp" />
<ClCompile Include="src\fheroes2\ai\normal\ai_normal_spell.cpp" />
<ClCompile Include="src\fheroes2\ai\ai_planner.cpp" />
<ClCompile Include="src\fheroes2\ai\ai_planner_castle.cpp" />
<ClCompile Include="src\fheroes2\ai\ai_planner_hero.cpp" />
<ClCompile Include="src\fheroes2\ai\ai_planner_kingdom.cpp" />
<ClCompile Include="src\fheroes2\army\army.cpp" />
<ClCompile Include="src\fheroes2\army\army_bar.cpp" />
<ClCompile Include="src\fheroes2\army\army_troop.cpp" />
Expand Down Expand Up @@ -109,9 +108,17 @@
<ClCompile Include="src\fheroes2\editor\editor_interface.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_interface_panel.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_mainmenu.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_map_specs_window.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_object_popup_window.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_castle_details_window.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_daily_event_spec_window.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_daily_events_window.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_event_details_window.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_options.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_rumor_window.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_save_map_window.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_sphinx_window.cpp" />
<ClCompile Include="src\fheroes2\editor\editor_ui_helper.cpp" />
<ClCompile Include="src\fheroes2\editor\history_manager.cpp" />
<ClCompile Include="src\fheroes2\game\difficulty.cpp" />
<ClCompile Include="src\fheroes2\game\fheroes2.cpp" />
Expand Down Expand Up @@ -209,19 +216,6 @@
<ClCompile Include="src\fheroes2\monster\monster.cpp" />
<ClCompile Include="src\fheroes2\monster\monster_anim.cpp" />
<ClCompile Include="src\fheroes2\monster\monster_info.cpp" />
<ClCompile Include="src\fheroes2\objects\mounts.cpp" />
<ClCompile Include="src\fheroes2\objects\objcrck.cpp" />
<ClCompile Include="src\fheroes2\objects\objdirt.cpp" />
<ClCompile Include="src\fheroes2\objects\objdsrt.cpp" />
<ClCompile Include="src\fheroes2\objects\objgras.cpp" />
<ClCompile Include="src\fheroes2\objects\objlava.cpp" />
<ClCompile Include="src\fheroes2\objects\objmult.cpp" />
<ClCompile Include="src\fheroes2\objects\objsnow.cpp" />
<ClCompile Include="src\fheroes2\objects\objswmp.cpp" />
<ClCompile Include="src\fheroes2\objects\objtown.cpp" />
<ClCompile Include="src\fheroes2\objects\objwatr.cpp" />
<ClCompile Include="src\fheroes2\objects\objxloc.cpp" />
<ClCompile Include="src\fheroes2\objects\trees.cpp" />
<ClCompile Include="src\fheroes2\resource\artifact.cpp" />
<ClCompile Include="src\fheroes2\resource\artifact_info.cpp" />
<ClCompile Include="src\fheroes2\resource\artifact_ultimate.cpp" />
Expand Down Expand Up @@ -275,9 +269,12 @@
<ClInclude Include="src\fheroes2\agg\mus.h" />
<ClInclude Include="src\fheroes2\agg\til.h" />
<ClInclude Include="src\fheroes2\agg\xmi.h" />
<ClInclude Include="src\fheroes2\ai\ai.h" />
<ClInclude Include="src\fheroes2\ai\ai_battle.h" />
<ClInclude Include="src\fheroes2\ai\ai_common.h" />
<ClInclude Include="src\fheroes2\ai\ai_hero_action.h" />
<ClInclude Include="src\fheroes2\ai\ai_personality.h" />
<ClInclude Include="src\fheroes2\ai\normal\ai_normal.h" />
<ClInclude Include="src\fheroes2\ai\ai_planner.h" />
<ClInclude Include="src\fheroes2\ai\ai_planner_internals.h" />
<ClInclude Include="src\fheroes2\army\army.h" />
<ClInclude Include="src\fheroes2\army\army_bar.h" />
<ClInclude Include="src\fheroes2\army\army_troop.h" />
Expand Down Expand Up @@ -317,12 +314,20 @@
<ClInclude Include="src\fheroes2\dialog\dialog_selectitems.h" />
<ClInclude Include="src\fheroes2\dialog\dialog_selectscenario.h" />
<ClInclude Include="src\fheroes2\dialog\dialog_system_options.h" />
<ClInclude Include="src\fheroes2\editor\editor.h" />
<ClInclude Include="src\fheroes2\editor\editor_interface.h" />
<ClInclude Include="src\fheroes2\editor\editor_interface_panel.h" />
<ClInclude Include="src\fheroes2\editor\editor_mainmenu.h" />
<ClInclude Include="src\fheroes2\editor\editor_map_specs_window.h" />
<ClInclude Include="src\fheroes2\editor\editor_object_popup_window.h" />
<ClInclude Include="src\fheroes2\editor\editor_daily_event_spec_window.h" />
<ClInclude Include="src\fheroes2\editor\editor_daily_events_window.h" />
<ClInclude Include="src\fheroes2\editor\editor_castle_details_window.h" />
<ClInclude Include="src\fheroes2\editor\editor_event_details_window.h" />
<ClInclude Include="src\fheroes2\editor\editor_options.h" />
<ClInclude Include="src\fheroes2\editor\editor_rumor_window.h" />
<ClInclude Include="src\fheroes2\editor\editor_save_map_window.h" />
<ClInclude Include="src\fheroes2\editor\editor_sphinx_window.h" />
<ClInclude Include="src\fheroes2\editor\editor_ui_helper.h" />
<ClInclude Include="src\fheroes2\editor\history_manager.h" />
<ClInclude Include="src\fheroes2\game\difficulty.h" />
<ClInclude Include="src\fheroes2\game\game.h" />
Expand Down Expand Up @@ -413,19 +418,6 @@
<ClInclude Include="src\fheroes2\monster\monster.h" />
<ClInclude Include="src\fheroes2\monster\monster_anim.h" />
<ClInclude Include="src\fheroes2\monster\monster_info.h" />
<ClInclude Include="src\fheroes2\objects\mounts.h" />
<ClInclude Include="src\fheroes2\objects\objcrck.h" />
<ClInclude Include="src\fheroes2\objects\objdirt.h" />
<ClInclude Include="src\fheroes2\objects\objdsrt.h" />
<ClInclude Include="src\fheroes2\objects\objgras.h" />
<ClInclude Include="src\fheroes2\objects\objlava.h" />
<ClInclude Include="src\fheroes2\objects\objmult.h" />
<ClInclude Include="src\fheroes2\objects\objsnow.h" />
<ClInclude Include="src\fheroes2\objects\objswmp.h" />
<ClInclude Include="src\fheroes2\objects\objtown.h" />
<ClInclude Include="src\fheroes2\objects\objwatr.h" />
<ClInclude Include="src\fheroes2\objects\objxloc.h" />
<ClInclude Include="src\fheroes2\objects\trees.h" />
<ClInclude Include="src\fheroes2\resource\artifact.h" />
<ClInclude Include="src\fheroes2\resource\artifact_info.h" />
<ClInclude Include="src\fheroes2\resource\artifact_ultimate.h" />
Expand Down
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ dependencies {
implementation project(':isotools')
implementation project(':sdl2')

implementation group: 'commons-io', name: 'commons-io', version: '2.15.1'
implementation group: 'commons-io', name: 'commons-io', version: '2.16.1'

implementation 'com.google.android.material:material:1.11.0'
implementation 'com.google.android.material:material:1.12.0'
}

tasks.register('copyH2D', Copy) {
Expand Down
12 changes: 11 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto">

<!-- OpenGL ES 2.0 -->
Expand Down Expand Up @@ -46,7 +47,8 @@
android:process=":GameActivityProcess"
android:screenOrientation="sensorLandscape"
android:taskAffinity="org.fheroes2.GameTask"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
tools:ignore="DiscouragedApi,UnusedAttribute">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down Expand Up @@ -81,5 +83,13 @@
android:label="@string/activity_save_file_manager_label"
android:taskAffinity="org.fheroes2.ToolsetTask"
android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar" />

<activity
android:name=".MapFileManagerActivity"
android:exported="false"
android:icon="@mipmap/ic_launcher_toolset"
android:label="@string/activity_map_file_manager_label"
android:taskAffinity="org.fheroes2.ToolsetTask"
android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar" />
</application>
</manifest>
146 changes: 146 additions & 0 deletions android/app/src/main/java/org/fheroes2/FileManagement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2024 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/

package org.fheroes2;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.function.Predicate;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

import org.apache.commons.io.IOUtils;

final class FileManagement
{
private FileManagement()
{
throw new IllegalStateException( "Instantiation is not allowed" );
}

static List<String> getFileList( final File fileDir, final List<String> allowedFileExtensions )
{
final List<String> result = new ArrayList<>();

final File[] fileList = fileDir.listFiles( ( dir, name ) -> {
if ( !dir.equals( fileDir ) ) {
return false;
}

final String lowercaseName = name.toLowerCase( Locale.ROOT );

for ( final String extension : allowedFileExtensions ) {
if ( lowercaseName.endsWith( extension ) ) {
return true;
}
}

return false;
} );

if ( fileList != null ) {
for ( final File file : fileList ) {
if ( file.isFile() ) {
result.add( file.getName() );
}
}

Collections.sort( result );
}

return result;
}

/**
* The directory structure will not be preserved when importing. All matching files will be imported directly into the target directory.
*
* @return true if at least one matching file was found and imported, otherwise returns false
*/
static boolean importFilesFromZip( final File fileDir, final List<String> allowedFileExtensions, final InputStream zipStream ) throws IOException
{
final Predicate<String> checkExtension = ( String name ) ->
{
final String lowercaseName = name.toLowerCase( Locale.ROOT );

for ( final String extension : allowedFileExtensions ) {
if ( lowercaseName.endsWith( extension ) ) {
return true;
}
}

return false;
};

boolean result = false;

try ( final ZipInputStream zin = new ZipInputStream( zipStream ) ) {
Files.createDirectories( fileDir.toPath() );

for ( ZipEntry zEntry = zin.getNextEntry(); zEntry != null; zEntry = zin.getNextEntry() ) {
if ( zEntry.isDirectory() ) {
continue;
}

final String zEntryFileName = new File( zEntry.getName() ).getName();
if ( !checkExtension.test( zEntryFileName ) ) {
continue;
}

try ( final OutputStream out = Files.newOutputStream( ( new File( fileDir, zEntryFileName ) ).toPath() ) ) {
IOUtils.copy( zin, out );
}

result = true;
}
}

return result;
}

static void exportFilesToZip( final File fileDir, final List<String> fileNames, final OutputStream zipStream ) throws IOException
{
try ( final ZipOutputStream zout = new ZipOutputStream( zipStream ) ) {
for ( final String fileName : fileNames ) {
zout.putNextEntry( new ZipEntry( fileName ) );

try ( final InputStream in = Files.newInputStream( ( new File( fileDir, fileName ) ).toPath() ) ) {
IOUtils.copy( in, zout );
}
}
}
}

static void deleteFiles( final File fileDir, final List<String> fileNames ) throws IOException
{
for ( final String fileName : fileNames ) {
final File file = new File( fileDir, fileName );

Files.deleteIfExists( file.toPath() );
}
}
}
Loading

0 comments on commit 38c5915

Please sign in to comment.