Merge pull request #9298 from Ebola16/AClearLog

Android: Clear Log file
This commit is contained in:
LC 2020-11-30 09:34:57 -05:00 committed by GitHub
commit ea2ec64ab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

View File

@ -39,8 +39,13 @@ import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.SingleChoiceVie
import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.SliderViewHolder;
import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.SubmenuViewHolder;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
import org.dolphinemu.dolphinemu.utils.Log;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.HashSet;
@ -339,6 +344,22 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
mView.onSettingChanged();
}
public static void clearLog()
{
// Don't delete the log in case it is being monitored by another app.
File log = new File(DirectoryInitialization.getUserDirectory() + "/Logs/dolphin.log");
try
{
RandomAccessFile raf = new RandomAccessFile(log, "rw");
raf.setLength(0);
}
catch (IOException e)
{
Log.error("[SettingsAdapter] Failed to clear log file: " + e.getMessage());
}
}
private void handleMenuTag(MenuTag menuTag, int value)
{
if (menuTag != null)

View File

@ -638,6 +638,8 @@ public final class SettingsFragmentPresenter
() -> mView.getAdapter().setAllLogTypes(true)));
sl.add(new RunRunnable(R.string.log_disable_all, 0, R.string.log_disable_all_confirmation, 0,
() -> mView.getAdapter().setAllLogTypes(false)));
sl.add(new RunRunnable(R.string.log_clear, 0, R.string.log_clear_confirmation, 0,
SettingsAdapter::clearLog));
sl.add(new HeaderSetting(R.string.log_types, 0));
for (Map.Entry<String, String> entry : LOG_TYPE_NAMES.entrySet())

View File

@ -283,6 +283,8 @@
<string name="log_enable_all_confirmation">Are you sure you want to enable all log types?</string>
<string name="log_disable_all">Disable all Log Types</string>
<string name="log_disable_all_confirmation">Are you sure you want to disable all log types?</string>
<string name="log_clear">Clear Log file</string>
<string name="log_clear_confirmation">Are you sure you want to clear the log file?</string>
<string name="log_types">Log Types</string>
<!-- Debug -->