Example #1
0
        // cek jika file scriptmonkey sudah ada, jika tidak buat baru
        private void InitScriptmonkey()
        {
            Script s = new Script();

            if (!File.Exists(ScriptFile))
            {
                Utils.WriteFile(ScriptFile, JsonConvert.SerializeObject(s));
            }
            if (!Directory.Exists(ScriptPath))
            {
                Directory.CreateDirectory(ScriptPath);
            }
            if (!Directory.Exists(ResourcePath))
            {
                Directory.CreateDirectory(ResourcePath);
            }
            ReloadDataAsync();
        }
Example #2
0
 public void Save(bool immediate = false)
 {
     try
     {
         var data = JsonConvert.SerializeObject(Userscript);
         if (immediate)
         {
             Utils.WriteFile(ScriptFile, data);
         }
         else
         {
             Utils.WriteFileAsync(ScriptFile, data);
         }
     }
     catch (Exception ex)
     {
         Logger.w("Unable To Save", ex);
     }
 }
Example #3
0
        private void AskUpdateScriptsAsync(List <UserScript> toUpdate, List <ScriptWithContent> toUpdateTo)
        {
            Thread t = new Thread(() =>
            {
                //var frm = new AskUpdateScriptFrm();

                //for (var i = 0; i < toUpdate.Count; i++) { frm.listBox1.Items.Add($"{toUpdate[i].Name} - {toUpdate[i].Version} to {toUpdateTo[i].ScriptData.Version}");}

                //if (frm.ShowDialog() != DialogResult.OK) return;

                if (toUpdate.Count == 0)
                {
                    return;
                }

                for (int i = 0; i < toUpdate.Count; i++)
                {
                    // Delete existing backups
                    if (File.Exists(ScriptPath + toUpdate[i].Path + @".backup"))
                    {
                        File.Delete(ScriptPath + toUpdate[i].Path + @".backup");
                    }

                    // Move current file to backup
                    File.Move(ScriptPath + toUpdate[i].Path, ScriptPath + toUpdate[i].Path + @".backup");

                    try
                    {
                        // Save updated script
                        Utils.WriteFile(ScriptPath + toUpdate[i].Path, toUpdateTo[i].Content);
                    }
                    catch (Exception ex)
                    {
                        Logger.w("Unable to update script: ", ex);
                        // Something went wrong. Restore from backup
                        if (File.Exists(ScriptPath + toUpdate[i].Path))
                        {
                            File.Delete(ScriptPath + toUpdate[i].Path);
                        }

                        File.Copy(ScriptPath + toUpdate[i].Path + @".backup", ScriptPath + toUpdate[i].Path);
                    }

                    // Remove from cache
                    if (_scriptCache.ContainsKey(toUpdate[i].Path))
                    {
                        _scriptCache.Remove(toUpdate[i].Path);
                    }

                    // Update stored script with metadata of script updated to
                    for (int j = 0; j < AllScripts.Count; j++)
                    {
                        if (this[j].Path == toUpdate[i].Path)
                        {
                            toUpdateTo[i].ScriptData.Path = toUpdate[i].Path;
                            this[j] = toUpdateTo[i].ScriptData;
                            break;
                        }
                    }
                }
                Save(true);
                ReloadData();
            });

            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }
Example #4
0
        public void Save()
        {
            var book = JsonConvert.SerializeObject(ListBookmark);

            Utils.WriteFile(FileBookmark, book);
        }
Example #5
0
        public void Save()
        {
            var dl = JsonConvert.SerializeObject(downloads);

            Utils.WriteFile(downloadlog, dl);
        }