/* GenesisChess, an Android chess application
 * Copyright 2014, Justin Madru (justin.jdm64@gmail.com)
 *
 * 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://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.chess.genesis.data;

import android.content.*;
import android.content.pm.*;
import android.content.pm.PackageManager.NameNotFoundException;
import com.chess.genesis.*;

public final class UpgradeHandler
{
	private UpgradeHandler()
	{
	}

	public static void run(final Context context)
	{
	try {
		final PackageInfo pinfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);

		upgrade(context, Pref.getInt(context, R.array.pf_appVersion), pinfo.versionCode);
	} catch (final NameNotFoundException e) {
		throw new RuntimeException(e.getMessage(), e);
	}
	}

	private static void upgrade(final Context context, final int oldVer, final int newVer)
	{
		if (oldVer == newVer)
			return;

		final PrefEdit pref = new PrefEdit(context);

		if (oldVer < 28) {
			pref.putBool(R.array.pf_isLoggedIn);
			pref.putString(R.array.pf_username);
		}

		pref.putBool(R.array.pf_enableAds);
		pref.putInt(R.array.pf_appVersion, newVer);
		pref.commit();
	}
}

@@ -780,37 +780,45 @@
 Manager.
-NameNotFoundException
+*;%0Aimport com.chess.genesis.*
 ;%0Aimport
@@ -836,16 +836,21 @@
 genesis.
+view.
 *;%0A%0Apubl
@@ -1383,16 +1383,76 @@
 eturn;%0A%0A
+%09%09if (oldVer %3C 67) %7B%0A%09%09%09PieceImg.resetColors(context);%0A%09%09%7D%0A%0A
 %09%09final 

reset board colors on upgrade so all users get the new colors