Example #1
0
        public async void DeleteLocalFile(string subPath, Action <bool> onSuccess, Action <Exception> onFailure)
        {
            try {
                var filePath    = GetFullFromSubPath(subPath);
                var fileName    = Path.GetFileName(filePath);
                var verFileName = await GetVerFileNameFromFileName(fileName);

                var verFilePath = GetVerFilePath(filePath, verFileName);

                Log("Deleting any file and version file for " + subPath);
                if (File.Exists(filePath))
                {
                    await FileX.DeleteAsync(filePath);
                }
                if (File.Exists(verFilePath))
                {
                    await FileX.DeleteAsync(verFilePath);
                }

                onSuccess?.Invoke(true);
            }
            catch (Exception e) {
                onFailure?.Invoke(e);
            }
        }
Example #2
0
        public async void GetLocalVersion(string subPath, Action <string> onSuccess, Action <Exception> onFailure)
        {
            try {
                var filePath = GetFullFromSubPath(subPath);
                var fileName = Path.GetFileName(filePath);

                var verFileName = await GetVerFileNameFromFileName(fileName);

                var verFilePath = GetVerFilePath(filePath, verFileName);

                // If either file is not present, we delete both and return null
                if (!File.Exists(verFilePath) || !File.Exists(filePath))
                {
                    if (File.Exists(verFilePath))
                    {
                        await FileX.DeleteAsync(verFilePath);
                    }
                    if (File.Exists(filePath))
                    {
                        await FileX.DeleteAsync(filePath);
                    }

                    onSuccess?.Invoke(string.Empty);
                    return;
                }

                using (var reader = File.OpenText(verFilePath)) {
                    var fileText = await reader.ReadToEndAsync();

                    reader.Close();
                    Log("Fetched local version for " + subPath + ". Version is " + fileText);
                    onSuccess?.Invoke(fileText);
                }
            }
            catch (Exception e) {
                LogError("Could not fetch local version for " + subPath + " --> " + e);
                onFailure?.Invoke(e);
            }
        }
Example #3
0
        async UniTask <bool> IsLocalFileIntact(string subPath)
        {
            var filePath    = GetFullFromSubPath(subPath);
            var fileName    = Path.GetFileName(filePath);
            var verFileName = await GetVerFileNameFromFileName(fileName);

            var verFilePath = GetVerFilePath(filePath, verFileName);

            if (!File.Exists(filePath) || !File.Exists(verFilePath))
            {
                if (File.Exists(filePath))
                {
                    await FileX.DeleteAsync(filePath);
                }
                if (File.Exists(verFilePath))
                {
                    await FileX.DeleteAsync(verFilePath);
                }
                return(false);
            }
            return(true);
        }