private void m_AppFrame_OnTimer_Sub1(object sender, RscAppFrameTimerEventArgs e) { switch (e.Reason) { case "copy move files_Cancel": { m_AppFrame.SetStatusText("User canceled operation!", StatusColoring.Error); break; } case "copy move files": { int iRootLen = m_txtRootFldr.Text.Length; if (e.Pos == 0) { foreach (RscFileItemDesc itFldr in m_folders) { string sPart = itFldr.Path.Substring(iRootLen); if (sPart.Length > 0) { string sNewFolder = m_sCopyMoveDest; if (iRootLen == 0) { sNewFolder += "\\"; } sNewFolder += sPart; try { RscStore store = new RscStore(); store.CreateFolder(sNewFolder); } catch (Exception /*exc*/) { m_AppFrame.SetStatusText("ERR: Unable to copy folder stru near: " + sNewFolder, StatusColoring.Error); e.Completed = true; return; } } } e.Max = 1; } else { RscFileItemDesc it = m_files[e.Pos - 1]; string sErr = ""; try { string sCopyMoveTo = m_sCopyMoveDest; if (iRootLen == 0) { sCopyMoveTo += "\\"; } sCopyMoveTo += it.Path.Substring(iRootLen); RscStore store = new RscStore(); if (m_sCopyMove == "move") { store.MoveFileForce(it.Path, sCopyMoveTo); } else { store.CopyFileForce(it.Path, sCopyMoveTo); } } catch (Exception exc) { sErr = "Unable to " + m_sCopyMove + " file.\r\n" + exc.Message; } if (sErr.Length == 0) { m_files.RemoveAt(e.Pos - 1); if ((e.Pos - 1) < m_files.Count) { int iPos = e.Pos; e.Pos = iPos; //Denie subsys to increment... } else { e.Completed = true; } } else { it.LastError = sErr; //ReQuery... lbFiles.ItemsSource = null; lbFiles.ItemsSource = m_files; if ((e.Pos - 1) < (m_files.Count - 1)) { e.Max++; } else { e.Completed = true; } } if (e.Completed) { if (m_sCopyMove == "move") { if (m_files.Count == 0) //Otherwise error occured... { if (chbRecurse.IsChecked.Value) //Otherwise no sub-tree deletion... { int iIdx = (m_folders.Count - 1) + 1; for (;;) { iIdx--; if (iIdx < 0) { break; } try { if (m_folders[iIdx].Path.Substring(iRootLen).Length > 0) { RscStore store = new RscStore(); store.DeleteFolder(m_folders[iIdx].Path); } m_folders.RemoveAt(iIdx); } catch (Exception /*exc*/) { } } } } if (m_files.Count == 0) { m_AppFrame.SetStatusText("Move succeeded!", StatusColoring.Success); } else { m_AppFrame.SetStatusText("Move failed for some item(s)!", StatusColoring.Error); } } else { if (m_files.Count == 0) { m_AppFrame.SetStatusText("Copy succeeded!", StatusColoring.Success); } else { m_AppFrame.SetStatusText("Copy failed for some item(s)!", StatusColoring.Error); } } //Causes exception... //ListFiles(); ActionPanel.Visibility = Rsc.Collapsed; } } break; } case "delete files_Cancel": { m_AppFrame.SetStatusText("User canceled operation!", StatusColoring.Error); break; } case "delete files": { if (e.Pos >= m_files.Count) { e.Completed = true; } else { RscFileItemDesc it = m_files[e.Pos]; string sErr = ""; try { RscStore store = new RscStore(); store.DeleteFile(it.Path); } catch (Exception exc) { sErr = "Unable to delete file.\r\n" + exc.Message; } if (sErr.Length == 0) { m_files.RemoveAt(e.Pos); if (e.Pos < m_files.Count) { int iPos = e.Pos; e.Pos = iPos; //Denie subsys to increment... } else { e.Completed = true; } } else { it.LastError = sErr; //ReQuery... lbFiles.ItemsSource = null; lbFiles.ItemsSource = m_files; if (e.Pos < (m_files.Count - 1)) { e.Max++; } else { e.Completed = true; } } } if (e.Completed) { if (m_files.Count == 0) //Otherwise error occured... { if (chbRecurse.IsChecked.Value) //Otherwise no sub-tree deletion... { int iIdx = (m_folders.Count - 1) + 1; for (;;) { iIdx--; if (iIdx < 0) { break; } try { if (m_folders[iIdx].Path.Length > 0) { RscStore store = new RscStore(); store.DeleteFolder(m_folders[iIdx].Path); } m_folders.RemoveAt(iIdx); } catch (Exception /*exc*/) { } } } } if (m_files.Count == 0) { m_AppFrame.SetStatusText("Delete succeeded!", StatusColoring.Success); // // // if (m_sAutoOperation.Length > 0) { if (m_iAutoOpPath + 1 < m_asAutoOpPathes.Length) { m_iAutoOpPath++; m_txtRootFldr.Text = m_asAutoOpPathes[m_iAutoOpPath]; m_AppFrame.AutoClick(m_btnCycle, new System.Windows.RoutedEventHandler(m_btnCycle_Click)); } else { PrepareExit(); NavigationService.GoBack(); } } // // // } else { m_AppFrame.SetStatusText("Delete failed for some item(s)!", StatusColoring.Error); } //Causes exception... //ListFiles(); ActionPanel.Visibility = Rsc.Collapsed; } break; } } }
public void Create(string sPageNavTo, string sPageArgs, string sImage, string sStatus, string sIcoId = "") { RscStore store = new RscStore(); Guid gd = Guid.NewGuid(); string gdStr = gd.ToString(); string sPageUri = "/MainPage.xaml" + "?IcoGd=" + gdStr; if (sIcoId.Length > 0) { sPageUri += "&IcoId=" + sIcoId; } if (sIcoId.Length == 0) { string sStFldr = RscKnownFolders.GetTempPath("ShellTiles", ""); store.WriteTextFile(sStFldr + "\\" + gdStr + ".txt", sPageNavTo + "\r\n" + sPageArgs, true); } else { //To make it enumerable... string sStFldr = RscKnownFolders.GetTempPath("ShellTiles", ""); store.WriteTextFile(sStFldr + "\\" + gdStr + ".txt", sIcoId, true); } string sImageUri = sImage; string sImgUriFinal = sImageUri; if (sImageUri.Length > 0) { string sTileImg = gdStr; if (sImageUri.IndexOf("isostore:\\") >= 0) { sImageUri = sImageUri.Substring(10); sTileImg += RscStore.ExtensionOfPath(sImageUri); } else { sImageUri = sImageUri.Replace("Images/", "A:\\System\\Theme\\Current\\"); sImageUri = sImageUri.Replace(".jpg", ".png"); if (!store.FileExists(sImageUri)) { sImageUri = sImageUri.Replace(".png", ".jpg"); sTileImg += ".jpg"; } else { sTileImg += ".png"; } } string sTileImgPath = "A:\\Shared\\ShellContent"; store.CreateFolderPath(sTileImgPath); sTileImgPath += "\\" + sTileImg; store.CopyFileForce(sImageUri, sTileImgPath); sImgUriFinal = "isostore:/" + sTileImgPath.Substring(3).Replace('\\', '/'); } string sTitle = sStatus; if (sIcoId.Length > 0) { sTitle = ""; Brush brBk = null; Brush brFore = null; double dFontSize = 0; string sErr = ""; string sNotiTitle = ""; string sNotiContent = ""; string sNotiSound = ""; string sInfoToChngChk = ""; string sInfo = GetInfo(true, sIcoId, out brBk, out brFore, out dFontSize, out sErr, out sNotiTitle, out sNotiContent, out sNotiSound, false, null, out sInfoToChngChk); if (sInfo == "") { sInfo = "\n\n(N/A)"; } if (brBk == null) { brBk = new SolidColorBrush(Color.FromArgb(255, 32, 32, 32)); //Colors.Black ); } if (brFore == null) { brFore = new SolidColorBrush(Colors.White); } if (dFontSize > 0) { dFontSize = cdFontSize - cdFontSize_SmDiff; } else { dFontSize = cdFontSize; } if (sInfoToChngChk.Length == 0) { sInfoToChngChk = sInfo; } //To update only if info has changed... string sStCntFldr = RscKnownFolders.GetTempPath("ShellTiles", "Content"); store.WriteTextFile(sStCntFldr + "\\" + gdStr + ".txt", sInfo, true); string sTileImgPath = "A:\\Shared\\ShellContent"; store.CreateFolderPath(sTileImgPath); sTileImgPath += "\\" + gdStr + ".jpg"; store.DeleteFile(sTileImgPath); RenderText(sInfo, sTileImgPath, brBk, brFore, dFontSize); sImgUriFinal = "isostore:/" + sTileImgPath.Substring(3).Replace('\\', '/'); } //MessageBox.Show( "Title: " + sTitle + "\r\n" + "NavTo: " + sPageUri + "\r\n" + "Image: " + sImageUri ); StandardTileData initialData = new StandardTileData(); { if (sImgUriFinal.Length > 0) { initialData.BackgroundImage = new Uri(sImgUriFinal, UriKind.Absolute); } if (sTitle.Length > 0) { initialData.Title = sTitle; } } ShellTile.Create(new Uri(sPageUri, UriKind.Relative), initialData); }