public static void MoveFile(string fromPath, string toPath) { ProjectManager.AdvLog("Moving file from " + fromPath + " to " + toPath); // Are we moving a directory or just a file? bool isDir = File.GetAttributes(fromPath) == FileAttributes.Directory; // Check to make sure a file doesn't already exist at the toPath if (!isDir) { if (File.Exists(fromPath)) { if (!File.Exists(toPath)) { File.Move(fromPath, toPath); } else { // Plugins probably alread moved.. however there are duplicates still inside the project!! ProjectManager.AdvLog("Path to move plugins into already exists at " + toPath); // Delete the existing file File.Delete(fromPath); ProjectManager.AdvLog("Existing file at " + fromPath + " has been deleted!"); } } else { // Plugins probably already moved.. we just have to hope they're in the toPath from here or they're lost and need reimporting ProjectManager.AdvLog("Path to move plugins from doesn't exist at " + fromPath); } } else { if (Directory.Exists(fromPath)) { if (!Directory.Exists(toPath)) { Directory.Move(fromPath, toPath); } else { // Plugins probably already moved.. however there are duplicates still inside the project!! ProjectManager.AdvLog("Path to move plugins into already exists at " + toPath); // Delete the existing directory Directory.Delete(fromPath, true); ProjectManager.AdvLog("Existing folder at " + fromPath + " has been deleted!"); } } else { // Plugins probably already moved.. we just have to hope they're in the toPath from here or they're lost and need reimporting ProjectManager.AdvLog("Path to move plugins from doesn't exist at " + fromPath); } } }
private void UpdatePluginList(bool DoLogs) { // The developer might have moved PluginImportData.json so search for it instead of using a fixed path string[] searchResults = AssetDatabase.FindAssets("PluginImportData"); string path = ""; if (searchResults.Length > 0) { // Just use the first path found and complain if there's multiple path = AssetDatabase.GUIDToAssetPath(searchResults [0]); if (searchResults.Length > 1) { ProjectManager.AdvLog("Multiple PluginImportData files found, make sure to delete any duplicates! (Using: " + path + ")"); } } else { Debug.LogError("Your project is missing PluginImportData.json! Your project will probably fail to build!"); return; } StreamReader reader = new StreamReader(path); pluginDataStorage = JsonUtility.FromJson <PluginInfo>(reader.ReadToEnd()); if (DoLogs) { for (int i = 0; i < pluginDataStorage.pluginInfo.Count; i++) { for (int globalPathId = 0; globalPathId < pluginDataStorage.pluginInfo [i].globalPathList.Count; globalPathId++) { ProjectManager.AdvLog(pluginDataStorage.pluginInfo [i].pluginName + " - globalPathList[" + globalPathId + "] - " + pluginDataStorage.pluginInfo [i].globalPathList [globalPathId]); } for (int iosPathId = 0; iosPathId < pluginDataStorage.pluginInfo [i].iosPathList.Count; iosPathId++) { ProjectManager.AdvLog(pluginDataStorage.pluginInfo [i].pluginName + " - iosPathList[" + iosPathId + "] - " + pluginDataStorage.pluginInfo [i].iosPathList [iosPathId]); } for (int androidPathId = 0; androidPathId < pluginDataStorage.pluginInfo [i].iosPathList.Count; androidPathId++) { ProjectManager.AdvLog(pluginDataStorage.pluginInfo [i].pluginName + " - androidPathList[" + androidPathId + "] - " + pluginDataStorage.pluginInfo [i].iosPathList [androidPathId]); } } Debug.Log("Finished reloading plugin list!"); } }
private void UpdateInstalledPackages() { ProjectManager.AdvLog("IAS Updating Installed Packages"); installedApps.Clear(); // Get all installed packages with a bundleId matching our filter string filteredPackageList = I6MediaPlugin.GetPackageList("com.pickle."); // Cleanup the package list mistakes (ending comma or any spaces) if (!string.IsNullOrEmpty(filteredPackageList)) { filteredPackageList = filteredPackageList.Trim(); // Trim whitespaces filteredPackageList = filteredPackageList.Remove(filteredPackageList.Length - 1); // Remove the unwanted comma at the end of the list // Split the list into a string array string[] packageArray = filteredPackageList.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (packageArray.Length > 0) { // Extract all packages and store them in the installedApps list foreach (string packageName in packageArray) { installedApps.Add(packageName.Trim().ToLowerInvariant()); } } else { Analytics.LogEvent("IAS", "No other installed packages found matching filter!"); } } else { Analytics.LogEvent("IAS", "Filtered package list was empty!"); } Analytics.SetUserProperty("ias_games_installed", installedApps.Count.ToString()); }
private static void ModifyPlugins(string value, bool doAdd, bool userAction = false) { ProjectManager.AdvLog("Modifying plugins: " + value + ", " + doAdd + ", " + userAction); // If this is an add action this must be done before any scripting defines are changed if (doAdd && (EditorApplication.isCompiling || EditorApplication.isUpdating)) { DisplayProgressBar(doAdd, false, value); } // Move plugins not in use outside of the assets folder // (I was just going to change their import platform settings but it was a pain to manage them for different platforms // so just keeping defaults and moving out of the assets folder will be fine + cleaner project with less projects active) List <string> activePlatformPluginFiles = GetPluginFiles(value, EditorUserBuildSettings.selectedBuildTargetGroup, true); List <string> otherPlatformPluginFiles = GetPluginFiles(value, EditorUserBuildSettings.selectedBuildTargetGroup, false); string projectPath = Application.dataPath.Replace("/Assets", ""); // Absolute path to the project with Assets folder removed e.g C:/Projects/My Game string disabledPluginsPath = projectPath + "/Disabled Plugins"; // C:/Projects/My Game/Disabled Plugins // Make sure the Disabled Plugins folder exists if (!Directory.Exists(disabledPluginsPath)) { Directory.CreateDirectory(disabledPluginsPath); } if (Directory.Exists(disabledPluginsPath)) { // Move plugins files for other platforms out of the project if (otherPlatformPluginFiles.Count > 0) { ProjectManager.AdvLog("There are " + otherPlatformPluginFiles.Count + " other plugin files to move out of the project!"); foreach (string file in otherPlatformPluginFiles) { ProjectManager.AdvLog("Moving " + file + " out of project!"); string insideProjectPath = "Assets/" + file; string outsideProjectPath = file; // Run GetAttributes within a try catch or if the file doesn't exist it'll throw an error (and we're calling this in the first place to see if the file exists ;_;) try { // Are we moving a directory or just a file? bool isDir = File.GetAttributes(projectPath + "/" + insideProjectPath) == FileAttributes.Directory; // Before we bother calculating any moving or folder creation check if the files we want to move out of the project are actually in the project already if (!isDir) { if (File.Exists(projectPath + "/" + insideProjectPath)) { // Get each folder as an array from the new file path so we can create all the nessesary folders string[] splitOutsidePath = outsideProjectPath.Split("/" [0]); // ["Plugins", "Android", "Example.aar"] string curPath = ""; // Minus 1 from the total iteration because the last value will be the actual file for (int i = 0; i < splitOutsidePath.Length - 1; i++) { curPath += "/" + splitOutsidePath [i]; if (!Directory.Exists(disabledPluginsPath + curPath)) { Directory.CreateDirectory(disabledPluginsPath + curPath); } } // All the folders should now be created and the files can be moved MoveFile(projectPath + "/" + insideProjectPath, disabledPluginsPath + "/" + outsideProjectPath); MoveFile(projectPath + "/" + insideProjectPath + ".meta", disabledPluginsPath + "/" + outsideProjectPath + ".meta"); } else { ProjectManager.AdvLog("File to be taken out of project not found at: " + projectPath + "/" + insideProjectPath); } } else { if (Directory.Exists(projectPath + "/" + insideProjectPath)) { // Get each folder as an array from the new file path so we can create all the nessesary folders string[] splitOutsidePath = outsideProjectPath.Split("/" [0]); // ["Plugins", "Android", "Example"] string curPath = ""; // Minus 1 from the total iteration because the last value will be the actual folder we're moving for (int i = 0; i < splitOutsidePath.Length - 1; i++) { curPath += "/" + splitOutsidePath [i]; if (!Directory.Exists(disabledPluginsPath + curPath)) { Directory.CreateDirectory(disabledPluginsPath + curPath); } } // All the folders should now be created and we can move the wanted directories into them MoveFile(projectPath + "/" + insideProjectPath, disabledPluginsPath + "/" + outsideProjectPath); MoveFile(projectPath + "/" + insideProjectPath + ".meta", disabledPluginsPath + "/" + outsideProjectPath + ".meta"); } else { ProjectManager.AdvLog("Directory to be moved out of project not found at: " + projectPath + "/" + insideProjectPath); } } } catch (System.Exception error) { ProjectManager.AdvLog("File or folder not found! " + error.Message); } } } // Move the plugin files for the active platform ProjectManager.AdvLog("The activePlatformPluginFiles has " + activePlatformPluginFiles.Count + " files to move"); if (activePlatformPluginFiles.Count > 0) { foreach (string file in activePlatformPluginFiles) { ProjectManager.AdvLog("Yay lets move " + file); // These variables are only relative to the assets folder (commented values are flipped if doAdd is false) string oldFullFilePath = (doAdd ? "Disabled Plugins/" : "Assets/") + file; // (if doAdd) Disabled Plugins/Plugins/Android/Example.aar string newFullFilePath = (doAdd ? "Assets/" : "Disabled Plugins/") + file; // (if doAdd) Assets/Plugins/Android/Example.aar // Run GetAttributes within a try catch or if the file doesn't exist it'll throw an error (and we're calling this in the first place to see if the file exists ;_;) try { // Are we moving to a directory or just a file? bool isDir = File.GetAttributes(projectPath + "/" + oldFullFilePath) == FileAttributes.Directory; // Before we bother calculating any moving or folder creation make sure the file we're wanting to move exist if (!isDir) { if (File.Exists(projectPath + "/" + oldFullFilePath)) { if (!doAdd) { newFullFilePath = newFullFilePath.Replace("Disabled Plugins/", ""); // Plugins/Android/Example.aar // Get each folder as an array from the new file path so we can create all the nessesary folders string[] splitNewPaths = newFullFilePath.Split("/" [0]); // ["Plugins", "Android", "Example.aar"] string curPath = ""; // Minus 1 from the total iteration because the last value will be the actual file for (int i = 0; i < splitNewPaths.Length - 1; i++) { curPath += "/" + splitNewPaths [i]; if (!Directory.Exists(disabledPluginsPath + curPath)) { Directory.CreateDirectory(disabledPluginsPath + curPath); } } // All the folders should now be created and the files can be moved MoveFile(projectPath + "/" + oldFullFilePath, disabledPluginsPath + "/" + newFullFilePath); MoveFile(projectPath + "/" + oldFullFilePath + ".meta", disabledPluginsPath + "/" + newFullFilePath + ".meta"); } else { MoveFile(projectPath + "/" + oldFullFilePath, projectPath + "/" + newFullFilePath); MoveFile(projectPath + "/" + oldFullFilePath + ".meta", projectPath + "/" + newFullFilePath + ".meta"); } } else { ProjectManager.AdvLog("File to be moved doesn't exist! (" + oldFullFilePath + ")"); } } else { if (Directory.Exists(projectPath + "/" + oldFullFilePath)) { if (!doAdd) { newFullFilePath = newFullFilePath.Replace("Disabled Plugins/", ""); // Plugins/Android/Example // Get each folder as an array from the new file path so we can create all the nessesary folders string[] splitNewPaths = newFullFilePath.Split("/" [0]); // ["Plugins", "Android", "Example"] string curPath = ""; // Minus 1 from the total iteration because the last value will be the actual folder for (int i = 0; i < splitNewPaths.Length - 1; i++) { curPath += "/" + splitNewPaths[i]; if (!Directory.Exists(disabledPluginsPath + curPath)) { Directory.CreateDirectory(disabledPluginsPath + curPath); } } // All the folders should now be created and the folder can be moved MoveFile(projectPath + "/" + oldFullFilePath, disabledPluginsPath + "/" + newFullFilePath); MoveFile(projectPath + "/" + oldFullFilePath + ".meta", disabledPluginsPath + "/" + newFullFilePath + ".meta"); } else { MoveFile(projectPath + "/" + oldFullFilePath, projectPath + "/" + newFullFilePath); MoveFile(projectPath + "/" + oldFullFilePath + ".meta", projectPath + "/" + newFullFilePath + ".meta"); } } else { ProjectManager.AdvLog("File to be moved doesn't exist! (" + oldFullFilePath + ")"); } } } catch (System.Exception error) { ProjectManager.AdvLog("File or folder not found! " + error.Message); } } } else { ProjectManager.AdvLog("This platform does not have any plugin files for " + value + "!"); } } else { ProjectManager.AdvLog("Failed to create Disabled Plugins folder or it was deleted whilst moving files!"); } // If this was a request to remove a plugin we now need to force re-add any files which still active plugins shared! if (!doAdd) { string[] ScriptingDefineSymbolNames = System.Enum.GetNames(typeof(ScriptingDefineSymbols)); for (int i = 0; i < ScriptingDefineSymbolNames.Length; i++) { ScriptingDefineSymbols curScriptingDefineSymbol = (ScriptingDefineSymbols)i; if (IsScriptingDefineSymbolActive(curScriptingDefineSymbol)) { ModifyScriptingDefineSymbol(curScriptingDefineSymbol, true, userAction, true); } } } // Force reload assets otherwise it'll wait for the user to click the Unity window again AssetDatabase.Refresh(ImportAssetOptions.Default); }
private IEnumerator DownloadIASData(bool cachedDataLoaded = false) { // Wait for an active internet connection while (Application.internetReachability == NetworkReachability.NotReachable) { yield return(null); } ProjectManager.AdvLog("IAS downloading data.."); // Iterate through each JSON file for (int jsonFileId = 0; jsonFileId < jsonUrls.Length; jsonFileId++) { // Download the JSON file WWW wwwJSON = new WWW(jsonUrls[jsonFileId]); // Wait for the JSON data to be downloaded yield return(wwwJSON); // Check for any errors if (!string.IsNullOrEmpty(wwwJSON.error)) { Analytics.LogError("IAS", "JSON download error! " + wwwJSON.error); yield break; } else if (wwwJSON.text.Contains("There was an error")) { Analytics.LogError("IAS", "JSON download error! Serverside system error!"); yield break; } else if (string.IsNullOrEmpty(wwwJSON.text)) { Analytics.LogError("IAS", "JSON download error! Empty JSON!"); yield break; } JsonFileData tempAdvertData = JsonUtility.FromJson <JsonFileData>(wwwJSON.text); // Dispose of the wwwJSON data (clear it from memory) wwwJSON.Dispose(); if (tempAdvertData == null) { Analytics.LogError("IAS", "Temp advert data was null!"); yield break; } if (!DoesSlotFileIdExist(jsonFileId)) { advertData.Add(new AdJsonFileData()); } bool needToReloadAdSlots = !cachedDataLoaded; bool needToRandomizeSlot = false; // We're currently only using the slots, not containers for (int i = 0; i < tempAdvertData.slots.Count; i++) { JsonSlotData curSlot = tempAdvertData.slots[i]; // We'll be converting the slot id (e.g 1a, 1c or 2f) into just number and just character values int slotInt; char slotChar; // Attempt to extract the slot int from the slot id if (!int.TryParse(Regex.Replace(curSlot.slotid, "[^0-9]", ""), out slotInt)) { Analytics.LogError("IAS", "Failed to parse slot int from '" + curSlot.slotid + "'"); yield break; } // Attempt to extract the slot character from the slot id if (!char.TryParse(Regex.Replace(curSlot.slotid, "[^a-z]", ""), out slotChar)) { Analytics.LogError("IAS", "Failed to parse slot char from '" + curSlot.slotid + "'"); yield break; } // If this slot doesn't exist yet create a new slot for it if (!DoesSlotIntExist(jsonFileId, slotInt)) { advertData[jsonFileId].slotInts.Add(new AdSlotData(slotInt, new List <AdData>())); } // Get the index in the list for slotInt int slotDataIndex = GetSlotIndex(jsonFileId, slotInt); if (slotDataIndex < 0) { Analytics.LogError("IAS", "Failed to get slotDataIndex!"); yield break; } // Make sure this slot char isn't repeated in the json file within this slot int for some reason if (!DoesSlotCharExist(jsonFileId, slotInt, slotChar)) { advertData[jsonFileId].slotInts[slotDataIndex].advert.Add(new AdData(slotChar)); needToRandomizeSlot = true; } int slotAdIndex = GetAdIndex(jsonFileId, slotInt, slotChar); if (slotAdIndex < 0) { Analytics.LogError("IAS", "Failed to get slotAdIndex! Could not find " + slotInt + ", " + slotChar.ToString()); yield break; } AdData curAdData = advertData[jsonFileId].slotInts[slotDataIndex].advert[slotAdIndex]; // Extract the bundleId of the advert #if UNITY_ANDROID // Regex extracts the id GET request from the URL which is the package name of the game // (replaces everything that does NOT match id=blahblah END or NOT match id=blahblah AMERPERSAND string packageName = Regex.Match(curSlot.adurl, "(?<=id=)((?!(&|\\?)).)*").Value; #elif UNITY_IOS // IOS we just need to grab the name after the hash in the URL string packageName = Regex.Match(curSlot.adurl, "(?<=.*#).*").Value; #else // For other platforms we should be fine to just use the full URL for package name comparisons as we'll be using .Compare // And other platforms won't include any other referral bundle ids in their URLs string packageName = curSlot.adurl; #endif string imageFileType = Regex.Match(curSlot.imgurl, "(?<=/uploads/adverts/.*)\\.[A-z]*[^(\\?|\")]").Value; curAdData.fileName = curSlot.slotid + imageFileType; curAdData.isSelf = packageName.Contains(bundleId); curAdData.isActive = curSlot.active; curAdData.isInstalled = IsPackageInstalled(packageName); curAdData.adUrl = curSlot.adurl; curAdData.packageName = packageName; curAdData.imgUrl = curSlot.imgurl; if (curAdData.newUpdateTime < curSlot.updatetime || curAdData.newUpdateTime == 0L) { needToReloadAdSlots = true; } curAdData.newUpdateTime = curSlot.updatetime; // I'm not pre-downloading all the images here because it takes quite a long time to download even on our fast ethernet connection (~15 seconds) // So I think it's best to download the images (if needed) when the ads are called to be refreshed } if (needToRandomizeSlot) { RandomizeAdSlots(jsonFileId); } if (needToReloadAdSlots) { RefreshActiveAdSlots(jsonFileId); } } SaveIASData(); ProjectManager.AdvLog("IAS Done"); }