Beispiel #1
0
        public static void Proceed(filetype filetype, string filenameOrConnectionString, Item source, string[] categories = null)
        {
            switch (filetype)
            {
            case filetype.CSV:
            {
                CSV csvFile = new CSV(filenameOrConnectionString);
                csvFile.New();
                csvFile.Save(source);
            }
            break;

            case filetype.XML:
            {
                XML xmlFile = new XML(filenameOrConnectionString);
                xmlFile.New();
                xmlFile.Save(source);
            }
            break;

            case filetype.MySQL:
            {
                Database db = new Database(filenameOrConnectionString);
                db.FillTables();
                foreach (Seznam item in source.GetItemsList())
                {
                    db.AddRecord(item.Nazev, item.Kategorie, item.Obsah);
                }
                db.Save();
            }
            break;
            }
        }
Beispiel #2
0
        public ActionResult filetypeDeleteConfirmed(int id)
        {
            filetype filetype = db.filetypes.Find(id);

            db.filetypes.Remove(filetype);
            db.SaveChanges();
            return(RedirectToAction("filetypeList"));
        }
Beispiel #3
0
 public ActionResult filetypeEdit([Bind(Include = "Id,name")] filetype filetype)
 {
     if (ModelState.IsValid)
     {
         db.Entry(filetype).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("filetypeList"));
     }
     return(View(filetype));
 }
Beispiel #4
0
        public ActionResult filetypeCreate([Bind(Include = "Id,name")] filetype filetype)
        {
            if (ModelState.IsValid)
            {
                db.filetypes.Add(filetype);
                db.SaveChanges();
                return(RedirectToAction("filetypeList"));
            }

            return(View(filetype));
        }
Beispiel #5
0
 public bool AllowedToSave(filetype type)
 {
     return (type == filetype.resources && set.CacheResourceFiles > 1) ||
             (type == filetype.entry_large && set.CacheEntryFiles > 1) ||
             (type == filetype.port_main && set.CachePortFiles > 1) ||
             (type == filetype.scenes && set.CacheSceneFiles > 1) ||
             (type == filetype.sound && set.CacheSoundFiles > 1) ||
             (type == filetype.title_call ||
             type == filetype.world_name ||
             type == filetype.image) && set.CacheResourceFiles > 1;
 }
Beispiel #6
0
 public void InsertFiletype(filetype filetype)
 {
     if ((filetype.EntityState != EntityState.Detached))
     {
         this.ObjectContext.ObjectStateManager.ChangeObjectState(filetype, EntityState.Added);
     }
     else
     {
         this.ObjectContext.filetype.AddObject(filetype);
     }
 }
Beispiel #7
0
 public bool AllowedToSave(filetype type)
 {
     return((type == filetype.resources && set.CacheResourceFiles > 1) ||
            (type == filetype.entry_large && set.CacheEntryFiles > 1) ||
            (type == filetype.port_main && set.CachePortFiles > 1) ||
            (type == filetype.scenes && set.CacheSceneFiles > 1) ||
            (type == filetype.sound && set.CacheSoundFiles > 1) ||
            (type == filetype.title_call ||
             type == filetype.world_name ||
             type == filetype.image) && set.CacheResourceFiles > 1);
 }
Beispiel #8
0
 public void DeleteFiletype(filetype filetype)
 {
     if ((filetype.EntityState != EntityState.Detached))
     {
         this.ObjectContext.ObjectStateManager.ChangeObjectState(filetype, EntityState.Deleted);
     }
     else
     {
         this.ObjectContext.filetype.Attach(filetype);
         this.ObjectContext.filetype.DeleteObject(filetype);
     }
 }
Beispiel #9
0
        // GET: filetypes/Delete/5
        public ActionResult filetypeDelete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            filetype filetype = db.filetypes.Find(id);

            if (filetype == null)
            {
                return(HttpNotFound());
            }
            return(View(filetype));
        }
        private async void continuebtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                locationmsg.Visibility   = Visibility.Collapsed;
                buttons.Visibility       = Visibility.Collapsed;
                imagesbtn.IsEnabled      = false;
                continuebtn.IsEnabled    = false;
                progress.Visibility      = Visibility.Visible;
                status.Visibility        = Visibility.Visible;
                progress.IsIndeterminate = true;

                App.BootleggerApp.OnFileDownloadProgress += BootleggerApp_OnFileDownloadProgress;
                App.BootleggerApp.OnDownloadProgress     += BootleggerApp_OnDownloadProgress;
                App.BootleggerApp.OnNextDownload         += BootleggerApp_OnNextDownload;

                if (!App.BootleggerApp.IsDockerInstalled)
                {
                    status.Text = Strings.DownloadingDocker;
                    CURRENTFILE = filetype.DOCKER;
                    //await App.BootleggerApp.DownloadInstaller(cancel.Token);
                    throw new DockerNotRunningException();
                    //status.Text = Strings.InstallingDocker;
                    //await App.BootleggerApp.RunInstaller(cancel.Token);
                }

                if (isupdate)
                {
                    await App.BootleggerApp.StopServer();
                }

                status.Text = Strings.StartingDocker;

                progress.IsIndeterminate = true;

                await App.BootleggerApp.StartDocker(cancel.Token);

                status.Text = Strings.LoadingComponents;

                progress.IsIndeterminate = true;

                //if (remote_download)
                //{
                //    CURRENTFILE = filetype.TAR;
                //    await App.BootleggerApp.DownloadImagesTar(cancel.Token);
                //}

                //load images into system:
                await App.BootleggerApp.DownloadImages(false, cancel.Token);

                if (isupdate)
                {
                    await App.BootleggerApp.UpdateVolumes();
                }

                App.BootleggerApp.IsInstalled = true;

                (Application.Current.MainWindow as MainWindow)._mainFrame.Content = new Running();
            }
            catch (Exception ex)
            {
                App.BootleggerApp.Log.Error(ex);
                var tt = await(App.Current.MainWindow as MetroWindow).ShowMessageAsync(Strings.Error, string.Format(Strings.ErrorDialog, ex.Message), MessageDialogStyle.Affirmative);
                Environment.Exit(1);
                //Console.WriteLine(ex.Message);
            }
        }
Beispiel #11
0
        /*/ - 缓存列表 -
         * private Dictionary<string, string> _cacheList;
         *
         * private const string CACHE_LIST_FILE = @"\CacheList.txt";
         * private string CacheListFile
         * {
         *      get { return settings.CacheFolder + CACHE_LIST_FILE; }
         * }
         *
         * public CacheCore() {
         *      LoadCacheList();
         * }
         *
         * /// <summary>
         * /// 读取缓存列表
         * /// </summary>
         * public void LoadCacheList() {
         *
         *      _cacheList = new Dictionary<string, string>();
         *
         *      if ( File.Exists( CacheListFile ) )
         *      {
         *              try
         *              {
         *                      foreach ( var line in File.ReadAllLines( CacheListFile ) )
         *                      {
         *                              int index = line.IndexOf( '?' );
         *                              if ( index > 0 )
         *                              {
         *
         *                                      _cacheList[line.Substring( 0, index )] = line.Substring( index + 1 );
         *
         *                              }
         *                      }
         *
         *                      Utility.Logger.Add( 2, "缓存列表载入完毕。" );
         *
         *              }
         *              catch ( Exception ex )
         *              {
         *                      Utility.ErrorReporter.SendErrorReport( ex, "读取缓存列表时出错。" );
         *              }
         *      }
         *
         * }
         *
         * /// <summary>
         * /// 保存缓存列表
         * /// </summary>
         * public void SaveCacheList() {
         *
         *      try
         *      {
         *              //if ( !Directory.Exists( "Settings" ) )
         *              //	Directory.CreateDirectory( "Settings" );
         *
         *              using ( var writer = new StreamWriter( CacheListFile, false, Encoding.UTF8 ) )
         *              {
         *                      foreach ( var kv in _cacheList )
         *                      {
         *                              writer.WriteLine( "{0}?{1}", kv.Key, kv.Value );
         *                      }
         *              }
         *
         *              Utility.Logger.Add( 2, "缓存列表已保存。" );
         *
         *      }
         *      catch ( Exception ex )
         *      {
         *              Utility.ErrorReporter.SendErrorReport( ex, "保存缓存列表时出错。" );
         *      }
         * }
         * //*/


        /// <summary>
        /// 对于一个新的客户端请求,根据url,决定下一步要对请求怎样处理
        /// </summary>
        /// <param name="url">请求的url</param>
        /// <param name="result">本地文件地址 or 记录的修改日期</param>
        /// <returns>下一步我们该做什么?忽略请求;返回缓存文件;验证缓存文件</returns>
        public Direction GotNewRequest(string url, out string result)
        {
            result = "";
            string filepath = "";

            Uri uri;

            try { uri = new Uri(url); } catch (Exception ex) {
                System.Diagnostics.Debug.WriteLine(ex);
                return(Direction.Discharge_Response);
                //url无效,忽略请求(不进行任何操作)
            }

            if (!uri.IsFilePath())
            {
                return(Direction.Discharge_Response);
                //url非文件,忽略请求
            }

            //识别文件类型
            filetype type = _RecognizeFileType(uri);

            if (type == filetype.unknown_file ||
                type == filetype.not_file ||
                type == filetype.game_entry)
            {
                return(Direction.Discharge_Response);
                //无效的文件,忽略请求
            }

            //检查Title Call与World Name的特殊地址
            if (settings.HackTitleEnabled)
            {
                if (type == filetype.title_call)
                {
                    filepath = uri.AbsolutePath.Replace('/', '\\');
                    filepath = filepath.Remove(filepath.LastIndexOf('\\')) + ".mp3";
                    filepath = settings.CacheFolder + filepath;
                    result   = filepath;

                    if (File.Exists(filepath))
                    {
                        return(Direction.Return_LocalFile);
                    }
                }
                else if (type == filetype.world_name)
                {
                    filepath = settings.CacheFolder + @"\kcs\resources\image\world.png";
                    result   = filepath;

                    if (File.Exists(filepath))
                    {
                        return(Direction.Return_LocalFile);
                    }
                }
            }

            //检查一般文件地址
            if ((type == filetype.resources && settings.CacheResourceFiles > 0) ||
                (type == filetype.entry_large && settings.CacheEntryFiles > 0) ||
                (type == filetype.port_main && settings.CachePortFiles > 0) ||
                (type == filetype.scenes && settings.CacheSceneFiles > 0) ||
                (type == filetype.sound && settings.CacheSoundFiles > 0) ||
                ((type == filetype.title_call ||
                  type == filetype.world_name ||
                  type == filetype.image) && settings.CacheResourceFiles > 0))
            {
                filepath = settings.CacheFolder + uri.AbsolutePath.Replace('/', '\\');

                /*/ 检查缓存列表中是否有对应版本
                 * string query = uri.PathAndQuery;
                 * int index = query.LastIndexOf( '?' );
                 * bool changed = false;
                 * if ( index > 0 ) {
                 *      string key = query.Substring( 0, index );
                 *      string value = query.Substring( index + 1 );
                 *
                 *      changed = _cacheList.ContainsKey( key ) && ( _cacheList[key] != query.Substring( index + 1 ) );
                 *      if ( _cacheList.ContainsKey( key ) ) {
                 *
                 *              if ( changed = ( _cacheList[key] != value ) ) {
                 *                      _cacheList[key] = value;
                 *              }
                 *
                 *      } else {
                 *              _cacheList[key] = value;
                 *      }
                 * }
                 * //*/

                //检查Hack文件地址
                if (settings.HackEnabled)
                {
                    var    fnext     = uri.Segments.Last().Split('.');
                    string hfilepath = filepath.Replace(uri.Segments.Last(), fnext[0] + ".hack." + fnext.Last());

                    if (File.Exists(hfilepath))
                    {
                        result = hfilepath;
                        return(Direction.Return_LocalFile);
                        //存在hack文件,则返回本地文件
                    }
                }

                //检查缓存文件
                if (File.Exists(filepath))
                {
                    //if ( changed ) {
                    //	// 版本发生变动,则重新下载
                    //	_RecordTask( url, filepath );
                    //	return Direction.Discharge_Response;
                    //}

                    //存在本地缓存文件 -> 检查文件的最后修改时间
                    //(验证所有文件 或 只验证非资源文件)
                    if (settings.CheckFiles > 1 || (settings.CheckFiles > 0 && type != filetype.resources))
                    {
                        //只有swf文件需要验证时间
                        if (filepath.EndsWith(".swf"))
                        {
                            //文件存在且需要验证时间
                            //-> 请求服务器验证修改时间(记录读取和保存的位置)
                            result = filepath;
                            _RecordTask(url, filepath);
                            return(Direction.Verify_LocalFile);
                        }
                    }

                    //文件不需验证
                    //->返回本地缓存文件
                    result = filepath;
                    return(type == filetype.sound ? Direction.NoCache_LocalFile : Direction.Return_LocalFile);
                }
                else
                {
                    //缓存文件不存在
                    //-> 下载文件 (记录保存地址)
                    _RecordTask(url, filepath);
                    return(Direction.Discharge_Response);
                }
            }

            //文件类型对应的缓存设置没有开启
            //-> 当做文件不存在
            return(Direction.Discharge_Response);
        }
Beispiel #12
0
 public void UpdateFiletype(filetype currentfiletype)
 {
     this.ObjectContext.filetype.AttachAsModified(currentfiletype, this.ChangeSet.GetOriginal(currentfiletype));
 }
Beispiel #13
0
        /// <summary>
        /// 对于一个新的客户端请求,根据url,决定下一步要对请求怎样处理
        /// </summary>
        /// <param name="url">请求的url</param>
        /// <param name="result">本地文件地址 or 记录的修改日期</param>
        /// <returns>下一步我们该做什么?忽略请求;返回缓存文件;验证缓存文件</returns>
        public Direction GotNewRequest(string url, out string result)
        {
            result = "";
            string filepath = "";

            Uri uri;

            try { uri = new Uri(url); }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
                return(Direction.Discharge_Response);
                //url无效,忽略请求(不进行任何操作)
            }

            if (!uri.IsFilePath())
            {
                return(Direction.Discharge_Response);
                //url非文件,忽略请求
            }

            //识别文件类型
            filetype type = _RecognizeFileType(uri);

            if (type == filetype.unknown_file ||
                type == filetype.not_file ||
                type == filetype.game_entry)
            {
                return(Direction.Discharge_Response);
                //无效的文件,忽略请求
            }

            //检查Title Call与World Name的特殊地址
            if (set.HackTitleEnabled)
            {
                if (type == filetype.title_call)
                {
                    filepath = uri.AbsolutePath.Replace('/', '\\');
                    filepath = filepath.Remove(filepath.LastIndexOf('\\')) + ".mp3";
                    filepath = myCacheFolder + filepath;
                    result   = filepath;

                    if (File.Exists(filepath))
                    {
                        return(Direction.Return_LocalFile);
                    }
                }
                else if (type == filetype.world_name)
                {
                    filepath = myCacheFolder + @"\kcs\resources\image\world.png";
                    result   = filepath;

                    if (File.Exists(filepath))
                    {
                        return(Direction.Return_LocalFile);
                    }
                }
            }

            //检查一般文件地址
            if ((type == filetype.resources && set.CacheResourceFiles > 0) ||
                (type == filetype.entry_large && set.CacheEntryFiles > 0) ||
                (type == filetype.port_main && set.CachePortFiles > 0) ||
                (type == filetype.scenes && set.CacheSceneFiles > 0) ||
                (type == filetype.sound && set.CacheSoundFiles > 0) ||
                ((type == filetype.title_call ||
                  type == filetype.world_name ||
                  type == filetype.image) && set.CacheResourceFiles > 0))
            {
                filepath = myCacheFolder + uri.AbsolutePath.Replace('/', '\\');

                //检查Hack文件地址
                if (set.HackEnabled)
                {
                    var    fnext     = uri.Segments.Last().Split('.');
                    string hfilepath = filepath.Replace(uri.Segments.Last(), fnext[0] + ".hack." + fnext.Last());

                    if (File.Exists(hfilepath))
                    {
                        result = hfilepath;
                        return(Direction.Return_LocalFile);
                        //存在hack文件,则返回本地文件
                    }
                }

                //检查缓存文件
                if (File.Exists(filepath))
                {
                    //存在本地缓存文件 -> 检查文件的最后修改时间
                    //(验证所有文件 或 只验证非资源文件)
                    if (set.CheckFiles > 1 || (set.CheckFiles > 0 && type != filetype.resources))
                    {
                        //检查文件时间
                        int i = VersionChecker.GetFileLastTime(uri, out result);

                        if (i == 1)
                        {
                            //存在这个文件的修改时间记录
                            //-> 请求服务器验证修改时间(记录读取和保存的位置)
                            _RecordTask(url, filepath);
                            return(Direction.Verify_LocalFile);
                        }
                        else if (i == 0)
                        {
                            //没有关于这个文件最后修改时间的记录
                            //-> 当做这个文件不存在
                            //-> 下载文件(记录保存地址)
                            _RecordTask(url, filepath);
                            return(Direction.Discharge_Response);
                        }
                        else
                        {
                            //文件类型不需要验证时间(只有swf验证)
                        }
                    }

                    //->返回本地缓存文件
                    result = filepath;
                    return(Direction.Return_LocalFile);
                }
                else
                {
                    //缓存文件不存在
                    //-> 下载文件 (记录保存地址)
                    _RecordTask(url, filepath);
                    return(Direction.Discharge_Response);
                }
            }

            //文件类型对应的缓存设置没有开启
            //-> 当做文件不存在
            return(Direction.Discharge_Response);
        }