Example #1
0
        public static void SaveIndex(int type)
        {
            string name     = (type < 1) ? "legacy" : "delete";
            string fileName = string.Concat(name, ".opt");

            Output.WriteAndLock(new Structures.Message()
            {
                Text = string.Format("Attempting to save: {0}.opt...", name)
            });

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            try { using (StreamWriter sW = new StreamWriter(File.Create(fileName))) { foreach (string entryName in legacyIndex)
                                                                                      {
                                                                                          sW.Write(string.Concat(entryName, "\n"));
                                                                                      }
                  } }
            catch (Exception ex) { Output.WriteAndUnlock(new Structures.Message()
                {
                    Text = string.Format("[Fail]\nError:{0}", ex.Message), AddBreak = true
                }); }
            finally { Output.WriteAndUnlock(new Structures.Message()
                {
                    Text = "[OK]", AddBreak = true
                }); }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        public static void SaveSettings()
        {
            Output.WriteAndLock(new Structures.Message()
            {
                Text = "Attempting to save: Portal.opt..."
            });

            if (File.Exists("portal.opt"))
            {
                File.Delete("portal.opt");
            }

            try
            {
                using (StreamWriter sW = new StreamWriter(File.Create("portal.opt")))
                {
                    foreach (KeyValuePair <string, string> pair in SettingsList)
                    {
                        sW.Write(string.Format("{0}:{1}\n", pair.Key, pair.Value));
                    }
                }
            }
            catch (Exception ex) { Output.WriteAndUnlock(new Structures.Message()
                {
                    Text = string.Format("[Fail]\nError: {0}", ex.Message), AddBreak = true
                }); }
            finally { Output.WriteAndUnlock(new Structures.Message()
                {
                    Text = "[OK]", AddBreak = true
                }); }
        }
Example #3
0
        public static void Build(bool rebuild)
        {
            Output.WriteAndLock(new Message()
            {
                Text = string.Format("{0} the Update Index...", (rebuild && OPT.GetBool("debug")) ? "Rebuilding" : "Building")
            });

            if (rebuild)
            {
                Program.Wait = true;
            }

            if (Index.Count > 0)
            {
                Index.Clear();
            }

            switch (OPT.GetInt("send.type"))
            {
            case 0:     // Google drive
                using (StreamReader sr = new StreamReader(File.Open(string.Format(@"{0}\{1}", System.IO.Directory.GetCurrentDirectory(), "gIndex.opt"), FileMode.Open, FileAccess.Read)))
                {
                    //string line;
                    //while ((line = sr.ReadLine()) != null)
                    //{
                    //    string[] optBlocks = line.Split('|');
                    //    if (optBlocks.Length == 4)
                    //    {
                    //        Index.Add(new IndexEntry { FileName = optBlocks[0], SHA512 = optBlocks[1], Legacy = Convert.ToBoolean(Convert.ToInt32(optBlocks[2])), Delete = Convert.ToBoolean(Convert.ToInt32(optBlocks[3])) });
                    //    }
                    //}
                }
                break;

            case 1:     // HTTP
                break;

            case 2:     // FTP
                break;

            case 3:     // TCP
                foreach (string filePath in System.IO.Directory.GetFiles(UpdatesDirectory))
                {
                    string fileName = Path.GetFileName(filePath);

                    Index.Add(new IndexEntry
                    {
                        FileName = fileName,
                        SHA512   = Hash.GetSHA512Hash(filePath),
                        Legacy   = OPT.IsLegacy(fileName),
                        Delete   = OPT.IsDelete(fileName)
                    });
                }
                break;
            }

            if (OPT.GetBool("debug"))
            {
                Output.WriteAndUnlock(new Message()
                {
                    Text = string.Format("[OK]\n\t- {0} files indexed", Count), AddBreak = true
                });
            }

            if (rebuild)
            {
                Program.Wait = false;
            }

            GUI.Instance.Invoke(new System.Windows.Forms.MethodInvoker(delegate {
                GUI.Instance.updatesViewBtn.Enabled = true;
                GUI.Instance.updatesView.Enabled    = true;
            }));
        }