Ejemplo n.º 1
0
        public void DeleteFiles(User user, EncounterMetadata metadata)
        {
            var folder = GetFolder(user, FileType.Data);

            if (!Directory.Exists(folder))
            {
                return;
            }
            var files = Directory.GetFiles(folder, $"{metadata.Filename}*");

            foreach (var file in files)
            {
                foreach (FileType fileType in Enum.GetValues(typeof(FileType)))
                {
                    if (!file.EndsWith($".{fileExtensionGetter.GetExtension(fileType)}",
                                       StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    File.Delete(file);
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        public void UpdateFilename(User user, EncounterMetadata metadata)
        {
            string oldFilePrefix = metadata.Filename;
            string newFilePrefix = metadata.GetDesiredFilename();

            if (newFilePrefix == oldFilePrefix)
            {
                return;
            }

            metadata.Filename = newFilePrefix;

            var folder = GetFolder(user, FileType.Data);

            if (!Directory.Exists(folder))
            {
                return;
            }
            var files = Directory.GetFiles(folder, $"{oldFilePrefix}*");

            foreach (var file in files)
            {
                // a better replacement should be used to prevent extra things from replaced
                // on Windows, this would only cause an error if the user folder shared a name with the file
                File.Move(file, file.Replace(oldFilePrefix, newFilePrefix));
            }
        }
Ejemplo n.º 3
0
        protected string GetFilepath(User user, FileType fileType, EncounterMetadata metadata)
        {
            var folder   = GetFolder(user, fileType);
            var filename = filenameGetter.GetFilename(fileType, metadata);

            return(Path.Combine(folder, filename));
        }
Ejemplo n.º 4
0
 public EncounterMetadata(EncounterMetadata baseEncounterInfo)
 {
     Categories.AddRange(baseEncounterInfo.Categories);
     Subtitle      = baseEncounterInfo.Subtitle;
     Description   = baseEncounterInfo.Description;
     Audience      = baseEncounterInfo.Audience;
     Difficulty    = baseEncounterInfo.Difficulty;
     EditorVersion = baseEncounterInfo.EditorVersion;
 }
        public virtual WaitableTask UnlockEncounter(User user, EncounterMetadata metadata)
        {
            var webRequest   = GetWebRequest(user, metadata);
            var serverOutput = serverReader.Begin(webRequest);
            var task         = new WaitableTask();

            serverOutput.AddOnCompletedListener((result) => ProcessResults(task, result));

            return(task);
        }
Ejemplo n.º 6
0
        protected virtual WWWForm CreateForm(User user, EncounterMetadata metadata)
        {
            var form = new WWWForm();

            form.AddField(ModeVariable, DeleteModeValue);
            form.AddField(AccountIdVariable, user.AccountId);
            form.AddField(RecordNumberVariable, metadata.RecordNumber);

            return(form);
        }
        public WaitableTask <EncounterNonImageContent> GetNonImageContent(User user, EncounterMetadata metadata)
        {
            var contentData = new WaitableTask <EncounterNonImageContent>();

            var webRequest   = GetWebRequest(user, metadata);
            var serverResult = serverReader.Begin(webRequest);

            serverResult.AddOnCompletedListener((result) => ProcessResults(contentData, result));

            return(contentData);
        }
Ejemplo n.º 8
0
        public WaitableTask <string> GetFileText(User user, FileType fileType, EncounterMetadata metadata)
        {
            var fileText = new WaitableTask <string>();

            var filePath     = GetFile(fileType, metadata.Filename);
            var webRequest   = UnityWebRequest.Get(filePath);
            var serverResult = serverReader.Begin(webRequest);

            serverResult.AddOnCompletedListener((result) => SetFileResult(result, fileText));
            return(fileText);
        }
Ejemplo n.º 9
0
        public WaitableTask <string> GetFileText(User user, FileType fileType, EncounterMetadata metadata)
        {
            var filepath = GetFilepath(user, fileType, metadata);

            if (!File.Exists(filepath))
            {
                return(new WaitableTask <string>(new Exception("File doesn't exist")));
            }
            var text = File.ReadAllText(filepath);

            return(new WaitableTask <string>(text));
        }
Ejemplo n.º 10
0
        public void SetFileText(User user, FileType fileType, EncounterMetadata metadata, string contents)
        {
            var filepath  = GetFilepath(user, fileType, metadata);
            var directory = Path.GetDirectoryName(filepath);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            File.WriteAllText(filepath, contents);
        }
        private UnityWebRequest GetWebRequest(User user, EncounterMetadata metadata)
        {
            var arguments = new UrlArgument[] {
                new UrlArgument(AccountIdVariable, user.AccountId.ToString()),
                new UrlArgument(ModeVariable, ModeValue),
                new UrlArgument(RecordNumberVariable, metadata.RecordNumber.ToString()),
                new UrlArgument(ColumnVariable, ColumnValue)
            };
            var url = urlBuilder.BuildUrl(DownloadPhp, arguments);

            return(UnityWebRequest.Get(url));
        }
Ejemplo n.º 12
0
        protected virtual UnityWebRequest GetWebRequest(User user, EncounterMetadata metadata)
        {
            var arguments = new UrlArgument[] {
                new UrlArgument(ModeVariable, ModeValue),
                new UrlArgument(AccountVariable, user.AccountId.ToString()),
                new UrlArgument(UsernameVariable, Environment.UserName),
                new UrlArgument(RecordNumberVariable, metadata.RecordNumber.ToString())
            };

            var url = urlBuilder.BuildUrl(LockPhp, arguments);

            return(UnityWebRequest.Get(url));
        }
        public WaitableTask <UserEncounter> GetUserEncounter(User user, EncounterMetadata metadata, EncounterBasicStatus basicStatus, SaveType saveType)
        {
            var encounterData  = dataReader.GetEncounter(user, metadata, saveType);
            var detailedStatus = detailedStatusReader.GetDetailedStatus(user, metadata, basicStatus);

            var encounter = new WaitableTask <UserEncounter>();

            void processResults() => ProcessResults(user, encounter, encounterData, detailedStatus);

            encounterData.AddOnCompletedListener((result) => processResults());
            detailedStatus.AddOnCompletedListener((result) => processResults());

            return(encounter);
        }
Ejemplo n.º 14
0
        protected virtual void AddFormModeFields(WWWForm form, EncounterMetadata metadata)
        {
            string mode;

            if (metadata.RecordNumber >= 0 && metadata.RecordNumber < 1000)
            {
                form.AddField(RecordNumberVariable, metadata.RecordNumber);
                mode = UpdateModeValue;
            }
            else
            {
                mode = UploadModeValue;
            }

            form.AddField(ModeVariable, mode);
        }
Ejemplo n.º 15
0
        public WaitableTask Delete(User user, EncounterMetadata metadata)
        {
            if (user.IsGuest)
            {
                return(WaitableTask.CompletedTask);
            }

            var url  = UrlBuilder.BuildUrl(PhpFile);
            var form = CreateForm(user, metadata);

            var webRequest    = UnityWebRequest.Post(url, form);
            var serverResults = ServerReader.Begin(webRequest);

            var result = new WaitableTask();

            serverResults.AddOnCompletedListener((serverResult) => ProcessResults(result, serverResult, metadata));
            return(result);
        }
Ejemplo n.º 16
0
        private void AddMetadata(Dictionary <int, Dictionary <SaveType, EncounterMetadata> > metadataGroups,
                                 SaveType saveType, EncounterMetadata metadata)
        {
            Dictionary <SaveType, EncounterMetadata> metadataGroup;

            if (metadataGroups.ContainsKey(metadata.RecordNumber))
            {
                metadataGroup = metadataGroups[metadata.RecordNumber];
            }
            else
            {
                metadataGroup = new Dictionary <SaveType, EncounterMetadata>();
                metadataGroups.Add(metadata.RecordNumber, metadataGroup);
            }

            if (!metadataGroup.ContainsKey(saveType))
            {
                metadataGroup.Add(saveType, metadata);
            }
        }
Ejemplo n.º 17
0
        protected virtual void AddMetadataFields(WWWForm form, EncounterMetadata metadata)
        {
            if (metadata is INamed named)
            {
                AddEscapedField(form, FirstNameVariable, named.Name.FirstName);
                AddEscapedField(form, LastNameVariable, named.Name.LastName);
            }
            else
            {
                AddEscapedField(form, TitleVariable, metadata.Title);
            }

            AddEscapedField(form, DifficultyVariable, metadata.Difficulty.ToString());
            AddEscapedField(form, SubtitleVariable, metadata.Subtitle);
            AddEscapedField(form, DescriptionVariable, metadata.Description);
            AddCategoryField(form, metadata.Categories);
            metadata.ResetDateModified();
            form.AddField(DateModifiedVariable, metadata.DateModified.ToString());
            AddEscapedField(form, AudienceVariable, metadata.Audience);
            AddEscapedField(form, VersionVariable, VersionValue);

            if (metadata is IWebCompletion webCompletion)
            {
                AddEscapedField(form, UrlVariable, webCompletion.Url);
                AddEscapedField(form, CompletionCodeVariable, webCompletion.CompletionCode);
            }

            form.AddField(PublicVariable, metadata.IsPublic);
            form.AddField(TemplateVariable, metadata.IsTemplate);
            if (metadata.Sprite == null)
            {
                return;
            }

            AddEscapedField(form, SpriteDataVariable, SpriteSerializer.Serialize(metadata.Sprite));
            form.AddField(SpriteWidthVariable, metadata.Sprite.texture.width);
            form.AddField(SpriteHeightVariable, metadata.Sprite.texture.height);

            form.AddField(GrantVariable, metadata.GrantInfo);
        }
 public WaitableTask Delete(User user, EncounterMetadata encounterMetadata)
 {
     LocalFileManager.DeleteFiles(user, encounterMetadata);
     AutosaveFileManager.DeleteFiles(user, encounterMetadata);
     return(WaitableTask.CompletedTask);
 }
Ejemplo n.º 19
0
 public EncounterMetadataSelectedEventArgs(EncounterMetadata metadata) => Metadata = metadata;
 protected abstract void Serialize(EncounterMetadata metadata);
 protected override void Serialize(EncounterMetadata metadata)
 => metadata.IsPublic = !Toggle.isOn;
Ejemplo n.º 22
0
        private void ProcessResults(WaitableTask actionResult, TaskResult <string> serverResult, EncounterMetadata metadata)
        {
            if (serverResult.IsError())
            {
                actionResult.SetError(serverResult.Exception);
                return;
            }

            Debug.Log("Returned text from PHP: \n" + serverResult.Value);
            if (string.IsNullOrWhiteSpace(serverResult.Value))
            {
                actionResult.SetError(new Exception("No text returned from the server."));
            }
            else if (!int.TryParse(serverResult.Value, out int recordNumber))
            {
                actionResult.SetError(new Exception(serverResult.Value));
            }
            else if (recordNumber != metadata.RecordNumber)
            {
                actionResult.SetError(new Exception("Did not get the correct metadata from the server."));
            }
            else
            {
                actionResult.SetCompleted();
            }
        }
Ejemplo n.º 23
0
 protected override void Serialize(EncounterMetadata metadata)
 => metadata.IsTemplate = Toggle.isOn;
Ejemplo n.º 24
0
        protected virtual void ProcessResults(WaitableTask actionResult, TaskResult <string> serverResult, EncounterMetadata metadata)
        {
            if (serverResult.IsError())
            {
                actionResult.SetError(serverResult.Exception);
                return;
            }

            Debug.Log("Returned text from PHP: \n" + serverResult.Value);
            if (string.IsNullOrWhiteSpace(serverResult.Value))
            {
                actionResult.SetError(new Exception("No text returned from the server."));
                return;
            }

            var splitStr = serverResult.Value.Split('|');

            if (int.TryParse(splitStr[0], out var recordNumber))
            {
                metadata.RecordNumber = recordNumber;
            }

            actionResult.SetCompleted();
        }
Ejemplo n.º 25
0
 public void SetFileText(User user, FileType fileType, EncounterMetadata metadata, string contents)
 => throw new Exception("Cannot write to demo files");
Ejemplo n.º 26
0
 public void DeleteFiles(User user, EncounterMetadata metadata)
 => throw new Exception("Cannot delete demo files");
Ejemplo n.º 27
0
 public void UpdateFilename(User user, EncounterMetadata metadata)
 => throw new Exception("Cannot update names of demo files");