/*
 * Copyright (c) 2015 LingoChamp Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.liulishuo.filedownloader;

import android.content.Context;

import com.liulishuo.filedownloader.util.FileDownloadLog;

import java.io.File;
import java.io.IOException;

public class PauseAllMarker {

    private static final String MAKER_FILE_NAME = ".filedownloader_pause_all_marker.b";

    @SuppressWarnings("ResultOfMethodCallIgnored")
    public static void createMarker(Context context) {
        final File markerFile = markerFile(context);
        if (!markerFile.getParentFile().exists()) markerFile.getParentFile().mkdirs();
        if (markerFile.exists()) {
            FileDownloadLog.w(PauseAllMarker.class, "marker file " + markerFile.getAbsolutePath() + " exists");
            return;
        }
        try {
            boolean success = markerFile.createNewFile();
            FileDownloadLog.d(PauseAllMarker.class, "create marker file" + markerFile.getAbsolutePath() + " " + success);
        } catch (IOException e) {
            FileDownloadLog.e(PauseAllMarker.class, "create marker file failed", e);
        }
    }

    private static File markerFile(Context context) {
        return new File(context.getCacheDir() + File.separator + MAKER_FILE_NAME);
    }

    public static boolean isMarked(Context context) {
        return markerFile(context).exists();
    }

    @SuppressWarnings("ResultOfMethodCallIgnored")
    public static void clearMarker(Context context) {
        final File file = markerFile(context);
        if (file.exists()) {
            FileDownloadLog.d(PauseAllMarker.class, "delete marker file " + file.delete());
        } else {
            FileDownloadLog.w(PauseAllMarker.class, "marker file doesn't exist");
        }
    }
}

@@ -894,16 +894,52 @@
 rker.b%22;
+%0A    private static File markerFile;
 %0A%0A    @S
@@ -1747,22 +1747,66 @@
         
-return
+if (markerFile == null) %7B%0A            markerFile =
  new Fil
@@ -1866,16 +1866,53 @@
 _NAME);%0A
+        %7D%0A        return markerFile;%0A
     %7D%0A%0A 

use lazy marker file instead of creating marker file every time